Thema: Delphi Problem mit Funktion

Einzelnen Beitrag anzeigen

fwsp
(Gast)

n/a Beiträge
 
#1

Problem mit Funktion

  Alt 4. Jan 2007, 19:10
hallo,

ich hab ein problem mit der funktion equal. Bei der Zeile
Code:
Result := equal(pop(S1), pop(S2));
meckert der compiler:
Code:
[Fehler] stackar.pas(90): Inkompatible Typen: 'STACK' und 'procedure, untyped pointer or untyped parameter'
Kann mir vllt jemand sagen warum?

danke sehr.

Delphi-Quellcode:
function equal(S1, S2: STACK): Boolean;
begin
  if isempty(S1) and isempty(S2) then
  begin
    Result := True;
  end
  else if isempty(S1) and not isempty(S2) then
  begin
    Result := False;
  end
  else if not isempty(S1) and isempty(S2) then
  begin
    Result := False;
  end
  else
  begin
    if (top(S1).val = top(S2).val) then
    begin
      Result := equal(pop(S1), pop(S2));
    end
    else
    begin
      Result := False;
    end;
  end;
end;
Delphi-Quellcode:
unit stackar;

interface

uses elemr;

const maxs = 5;

type STACK = record
                  elts : array [1..maxs] of ELEMENT;
                  ptr : integer;
             end;

procedure empty(var s : STACK);
procedure pop(var s : STACK);
function top(s : STACK) : ELEMENT;
procedure push(var s : STACK; e : ELEMENT);
function equal(S1, S2: STACK): Boolean;

implementation

function isempty(s : STACK) : boolean;
begin isempty := (s.ptr = 0) end;

procedure mkErrorst(var s : STACK);
begin s.ptr := maxs+1 end;

function iserror(s : STACK) : boolean;
begin iserror := (s.ptr > maxs) end;

procedure empty(var s : STACK);
begin s.ptr := 0 end;

function top(s : STACK) : ELEMENT;
begin
    if isempty(s) then begin
        top := errorel;
        writeln('Top: Stack Empty')
    end else if iserror(s) then begin
        top := errorel;
        writeln('Top: Stack broken')
    end else
        top := s.elts[s.ptr]
end;

procedure pop(var s : STACK);
begin
    if isempty(s) then begin
        writeln('Pop: Tried to pop from empty stack. Bang.');
        mkErrorst(s)
    end else if iserror(s) then
        writeln('Pop: Stack Empty') {do nothing}
    else
        s.ptr := pred(s.ptr)
end;

procedure push(var s : STACK; e : ELEMENT);
begin
    if iserrel(e) then
        writeln('Push: Bad element') {do nothing}
    else if iserror(s) then
        writeln('Push: Stack broken') {do nothing}
    else if s.ptr = maxs then begin
        writeln('Push: Stack overflow. Bang.'); {stack full}
        mkErrorst(s)
    end else begin
        s.ptr := succ(s.ptr);
        s.elts[s.ptr] := e
    end
end;

end.
Delphi-Quellcode:
unit elemr;

interface

type ELEMENT = record case elstate : (good,bad) of
                   good : (val : integer)
               end;

function errorel : ELEMENT;
function iserrel(e : ELEMENT) : boolean;
function mkel(v : integer) : ELEMENT;
function elval(e : ELEMENT) : integer;

implementation

function errorel : ELEMENT;
begin errorel.elstate := bad end;

function iserrel(e : ELEMENT) : boolean;
begin iserrel := e.elstate = bad end;

function mkel(v : integer) : ELEMENT;
begin mkel.elstate := good; mkel.val := v end;

function elval(e : ELEMENT) : integer;
begin
    if e.elstate = good then
        elval := e.val
    else begin
        writeln('Elval: Error element!');
        elval := -99
    end
end;

begin
    writeln('** Unit Elem: Integer Elements');
end.
Delphi-Quellcode:
program stackm(input, output);

{$APPTYPE CONSOLE}

uses elem, stackar;

var s : STACK;

begin
    writeln('** Main: Stack Demo');

    empty(s);
    push(s,1);
    push(s,2);
    writeln('1. Top: ',top(s));
    pop(s);
    writeln('2. Top: ',top(s));
    empty(s);
    pop(s);
    push(s,1);
    writeln('3. Top: ',top(s));
    empty(s);
    push(s,-99);
    writeln('4. Top: ',top(s));
end.
  Mit Zitat antworten Zitat