-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCLSSTACK.srvscr
72 lines (47 loc) · 1.55 KB
/
CLSSTACK.srvscr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/********************************************************************************
Description.. : a STACK LIFO datastructure. - Last In, First Out
Methods...... : size() - returns the length of the stack.
push() - adds a new element to the top of the stack
peek() - returns the top element
pop() - returns and removes the top element
Returns...... : -
Author....... : WOLANSKIP
Date......... : 2011-04-02
********************************************************************************
_______________________________________________________________________________
Modification. :
Author....... :
Date......... :
_______________________________________________________________________________
********************************************************************************/;
:CLASS Stack ;
:DECLARE _stack ;
:PROCEDURE constructor;
/* initialize the stack array ;
Me:_stack := {} ;
:ENDPROC;
:PROCEDURE size;
/* return the number of items on the stack ;
:RETURN LEN( Me:_stack ) ;
:ENDPROC;
:PROCEDURE peek;
/* peek returns the top element without popping it ;
/* copy the item to memory ;
item := Me:_stack[ LEN(Me:_stack) ] ;
:RETURN item ;
:ENDPROC;
:PROCEDURE push;
:PARAMETERS item ;
aAdd( Me:_stack, item ) ;
:ENDPROC;
:PROCEDURE pop ;
:DECLARE item;
:IF Len( Me:_stack ) = 0 ;
RaiseError( "Stack Size is Zero!", "DataStructures.clsStack:pop()", 12534 );
:ENDIF;
/* copy the item to memory ;
item := Me:peek() ;
/* Delete the last element ;
DelArray( Me:_stack, LEN(Me:_stack) ) ;
:RETURN item ;
:ENDPROC;