Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
66
Task/Stack/Oberon/stack-1.oberon
Normal file
66
Task/Stack/Oberon/stack-1.oberon
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
MODULE Stacks;
|
||||
IMPORT
|
||||
Object,
|
||||
Object:Boxed,
|
||||
Out := NPCT:Console;
|
||||
|
||||
TYPE
|
||||
Pool(E: Object.Object) = POINTER TO ARRAY OF E;
|
||||
Stack*(E: Object.Object) = POINTER TO StackDesc(E);
|
||||
StackDesc*(E: Object.Object) = RECORD
|
||||
pool: Pool(E);
|
||||
cap-,top: LONGINT;
|
||||
END;
|
||||
|
||||
PROCEDURE (s: Stack(E)) INIT*(cap: LONGINT);
|
||||
BEGIN
|
||||
NEW(s.pool,cap);s.cap := cap;s.top := -1
|
||||
END INIT;
|
||||
|
||||
PROCEDURE (s: Stack(E)) Top*(): E;
|
||||
BEGIN
|
||||
RETURN s.pool[s.top]
|
||||
END Top;
|
||||
|
||||
PROCEDURE (s: Stack(E)) Push*(e: E);
|
||||
BEGIN
|
||||
INC(s.top);
|
||||
ASSERT(s.top < s.cap);
|
||||
s.pool[s.top] := e;
|
||||
END Push;
|
||||
|
||||
PROCEDURE (s: Stack(E)) Pop*(): E;
|
||||
VAR
|
||||
resp: E;
|
||||
BEGIN
|
||||
ASSERT(s.top >= 0);
|
||||
resp := s.pool[s.top];DEC(s.top);
|
||||
RETURN resp
|
||||
END Pop;
|
||||
|
||||
PROCEDURE (s: Stack(E)) IsEmpty(): BOOLEAN;
|
||||
BEGIN
|
||||
RETURN s.top < 0
|
||||
END IsEmpty;
|
||||
|
||||
PROCEDURE (s: Stack(E)) Size*(): LONGINT;
|
||||
BEGIN
|
||||
RETURN s.top + 1
|
||||
END Size;
|
||||
|
||||
PROCEDURE Test;
|
||||
VAR
|
||||
s: Stack(Boxed.LongInt);
|
||||
BEGIN
|
||||
s := NEW(Stack(Boxed.LongInt),100);
|
||||
s.Push(NEW(Boxed.LongInt,10));
|
||||
s.Push(NEW(Boxed.LongInt,100));
|
||||
Out.String("size: ");Out.Int(s.Size(),0);Out.Ln;
|
||||
Out.String("pop: ");Out.Object(s.Pop());Out.Ln;
|
||||
Out.String("top: ");Out.Object(s.Top());Out.Ln;
|
||||
Out.String("size: ");Out.Int(s.Size(),0);Out.Ln
|
||||
END Test;
|
||||
|
||||
BEGIN
|
||||
Test
|
||||
END Stacks.
|
||||
Loading…
Add table
Add a link
Reference in a new issue