Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
39
Task/Stack/PL-I/stack.pli
Normal file
39
Task/Stack/PL-I/stack.pli
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* Any controlled variable may behave as a stack. */
|
||||
|
||||
declare s float controlled;
|
||||
|
||||
/* to push a value on the stack. */
|
||||
allocate s;
|
||||
s = 10;
|
||||
|
||||
/* To pop a value from the stack. */
|
||||
put (s);
|
||||
free s;
|
||||
|
||||
/* to peek at the top of stack> */
|
||||
put (s);
|
||||
|
||||
/* To see whether the stack is empty */
|
||||
if allocation(s) = 0 then ...
|
||||
|
||||
/* Note: popping a value from the stack, or peeking, */
|
||||
/* would usually require a check that the stack is not empty. */
|
||||
|
||||
/* Note: The above is a simple stack for S. */
|
||||
/* S can be any kind of data structure, an array, etc. */
|
||||
|
||||
/* Example to push ten values onto the stack, and then to */
|
||||
/* remove them. */
|
||||
|
||||
/* Push ten values, obtained from the input, onto the stack: */
|
||||
declare S float controlled;
|
||||
do i = 1 to 10;
|
||||
allocate s;
|
||||
get list (s);
|
||||
end;
|
||||
/* To pop those values from the stack: */
|
||||
do while (allocation(s) > 0);
|
||||
put skip list (s);
|
||||
free s;
|
||||
end;
|
||||
/* The values are printed in the reverse order, of course. */
|
||||
Loading…
Add table
Add a link
Reference in a new issue