|
A stack is a list of elements in which an element may be inserted or deleted only at one end called the top of the stack. This means, in particular that elements are removed from a stack in the reverse ordered of that in which they were inserted into the stack.
Special terminologies:
Push is the term used to insert an element into the stack.
Pop is the term used to delete an element from the stack.
Adding an Item Into Stack:
procedure push(item : items);
{add item to the global stack stack;
top is the current top of stack
and n is its maximum size}
begin
if top = n then OverFlow;
top := top+1;
stack(top) := item;
end: {of add}
Deleting an Item From Stack:
procedure pop(item : items);
{remove top element from the stack stack and put it in the item}
begin
if top = 0 then UnderFlow;
item := stack(top);
top := top-1;
end; {of delete}
|