mirror of
https://github.com/vishapoberon/vipak.git
synced 2026-04-05 20:42:26 +00:00
pointer stack works
This commit is contained in:
parent
1a573a5c83
commit
740bd75240
3 changed files with 55 additions and 16 deletions
|
|
@ -3,10 +3,14 @@ IMPORT List, Out, Sys;
|
|||
|
||||
TYPE
|
||||
integer* = Sys.integer;
|
||||
TObject* = Sys.TObject;
|
||||
|
||||
Node* = POINTER TO NodeDesc;
|
||||
NodeDesc* = List.NodeDesc;
|
||||
|
||||
TChar* = POINTER TO TCharDesc;
|
||||
|
||||
TCharDesc = RECORD (List.NodeDesc)
|
||||
TCharDesc = RECORD (Sys.TObjectDesc)
|
||||
char* : CHAR
|
||||
END;
|
||||
|
||||
|
|
@ -20,30 +24,48 @@ TYPE
|
|||
top: PROCEDURE(self: CharacterStackType) : CHAR;
|
||||
END;
|
||||
|
||||
PROCEDURE pop(self: CharacterStackType): CHAR;
|
||||
VAR
|
||||
ch: TChar;
|
||||
BEGIN
|
||||
NEW(ch);
|
||||
ch := self.Get(self, self.Count);
|
||||
self.Delete(self, self.Count);
|
||||
RETURN ch.char;
|
||||
END pop;
|
||||
characterStack: CharacterStackType;
|
||||
|
||||
PROCEDURE push(self: CharacterStackType; char: CHAR);
|
||||
VAR
|
||||
int: integer;
|
||||
ch: TChar;
|
||||
int: integer;
|
||||
BEGIN
|
||||
NEW(ch);
|
||||
ch.char := char;
|
||||
int := self.Add(self, ch);
|
||||
END push;
|
||||
|
||||
PROCEDURE pop(self: CharacterStackType): CHAR;
|
||||
VAR
|
||||
n: Node;
|
||||
BEGIN
|
||||
NEW(n);
|
||||
|
||||
IF self.Count = 0 THEN RETURN 0AX END;
|
||||
|
||||
n := self.Get(self, self.Count - 1);
|
||||
self.Delete(self, self.Count - 1);
|
||||
RETURN n.obj(TChar).char;
|
||||
END pop;
|
||||
|
||||
PROCEDURE top(self: CharacterStackType): CHAR;
|
||||
VAR
|
||||
n: Node;
|
||||
BEGIN
|
||||
NEW(n);
|
||||
|
||||
IF self.Count = 0 THEN RETURN 0AX END;
|
||||
|
||||
n := self.Get(self, self.Count - 1);
|
||||
RETURN n.obj(TChar).char;
|
||||
END top;
|
||||
|
||||
PROCEDURE Create* () : CharacterStackType;
|
||||
VAR l : CharacterStackType;
|
||||
BEGIN
|
||||
VAR
|
||||
l : CharacterStackType;
|
||||
BEGIN
|
||||
NEW(l);
|
||||
l.First := NIL;
|
||||
l.Last := NIL;
|
||||
|
|
@ -61,23 +83,39 @@ PROCEDURE Create* () : CharacterStackType;
|
|||
|
||||
l.pop := pop;
|
||||
l.push:= push;
|
||||
(* l.top := top; *)
|
||||
l.top := top;
|
||||
RETURN(l);
|
||||
END Create;
|
||||
|
||||
VAR
|
||||
characterStack: CharacterStackType;
|
||||
BEGIN
|
||||
NEW(characterStack);
|
||||
characterStack := Create();
|
||||
characterStack.push(characterStack, 'a');
|
||||
characterStack.push(characterStack, 'b');
|
||||
characterStack.push(characterStack, 'c');
|
||||
Out.Char(characterStack.pop(characterStack));
|
||||
|
||||
Out.Char(characterStack.top(characterStack));
|
||||
Out.Ln();
|
||||
Out.Char(characterStack.pop(characterStack));
|
||||
Out.Ln();
|
||||
Out.Char(characterStack.top(characterStack));
|
||||
Out.Ln();
|
||||
Out.Char(characterStack.pop(characterStack));
|
||||
Out.Ln();
|
||||
Out.Char(characterStack.top(characterStack));
|
||||
Out.Ln();
|
||||
Out.Char(characterStack.pop(characterStack));
|
||||
Out.Ln();
|
||||
Out.Char(characterStack.top(characterStack));
|
||||
Out.Ln();
|
||||
Out.Char(characterStack.pop(characterStack));
|
||||
Out.Ln();
|
||||
Out.Char(characterStack.top(characterStack));
|
||||
Out.Ln();
|
||||
Out.Char(characterStack.pop(characterStack));
|
||||
Out.Ln();
|
||||
Out.Char(characterStack.top(characterStack));
|
||||
Out.Ln();
|
||||
Out.Char(characterStack.pop(characterStack));
|
||||
Out.Ln();
|
||||
END CharaterStack.
|
||||
BIN
CharaterStack
Executable file
BIN
CharaterStack
Executable file
Binary file not shown.
1
diaspora2hugo
Submodule
1
diaspora2hugo
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 3fb4cbd410309ff341510171bdd6f154e767c01b
|
||||
Loading…
Add table
Add a link
Reference in a new issue