Like Queue, the Stack class is derived from Deque and redefines
certain methods. The elements of the stack are stored using a LIFO
(``last in, first out'') protocol.
1. Creation
Stack<Item>
s;
Create an empty Stack. O(1)
Stack<Item>
s2(s);
Create an empty Stack and initialize it with the
elements of s such that the elements will be popped
in the same order. O(n)
2. Operations
Item
top()
Returns the item on top of the Stack, without removing it. O(1)
Item
pop()
Returns the item on top of Stackand removes it. O(1)
void
push(Item& passed_item)
Pushes passed_item onto the top of the Stack. O(1)
void
insert(Item& passed_item)
Pushes passed_item onto the top of the Stack. This method overrides
the virtual function of the same name in Deque.
Bool
emptyQ()
Is the Stackempty? O(1)
void
clear()
Remove all the elements from the Stack. O(n)
Next:Graph Up:Edge Previous:QueueRHS Linux User 1/26/1998