|
B a c k t r a c k i n g u.s.w. Hilfsdatei ADT Stack
{ Deklaration eines dynamischen STACKS zum Gebrauch in verschiedenen
Programmen: BACKTR12.PAS
Im aufrufenden Programm muß zuvor der INHALTSTYP definiert werden. HMO, 1988 }
TYPE stacktyp = ^eintragstyp; { dynamische Liste }
eintragstyp = RECORD { Typ für einen Listeneintrag }
inhalt: inhaltstyp;
next : stacktyp
END;
{ S.1 }
PROCEDURE create_stack (VAR s: stacktyp);
BEGIN s:=NIL END;
{ S.2 }
FUNCTION empty_stack (s: stacktyp): Boolean;
BEGIN empty_stack := (s=NIL) END;
{ S.3 }
PROCEDURE push_stack (VAR s: stacktyp; inh: inhaltstyp);
VAR neu: stacktyp;
BEGIN
new(neu);
neu^.inhalt:=inh;
neu^.next:=s;
s:=neu
END;
{ S.4 }
PROCEDURE top_stack (s: stacktyp; VAR inh: inhaltstyp);
BEGIN inh:=s^.inhalt END;
{ S.5 }
PROCEDURE pop_stack (VAR s: stacktyp);
VAR alt: stacktyp;
BEGIN
alt:=s;
s:=s^.next;
dispose(alt)
END;
© HMO, Neubearbeitung Januar 1998 | ||||||||