Chapter 2 Stacks
What are the special names given to the two changes which can be made to the stack?
Push & Pop
When an item is removed...
it is popped from the stack
The operation peek is not really a new operation. It can be decomposed into...
A pop and a push
Sometimes called a last-in, first out (or LIFO) list?
A stack
Empty Stack
A stack which has no elements to pop
Stack
An ordered collection of items into which new items may be inserted and from which items may be deleted at one end, called the top
How can underflow be avoided?
By ensuring s.empty() is false before attempting the operation s.pop() or s.peek()
s.empty()
Determines whether or not a stack s is is empty. If the stack is empty, empty returns true; otherwise it returns false
When an item is added to a stack...
It is pushed onto the stack
If a record is needed of the intermediate items having been on the stack...
It must be kept elsewhere; it does not exist within the stack itself
The only way to determine if two stacks are equal is...
Remove all the elements and compare them individually
s.peek()
Returns the top element of stack s without changing the stack
Before applying the pop or peek operator to a stack, we must ensure...
That the stack is not empty
What is the upper limit on the number of items that may be kept on a stack?
The definition of a stack does not specify how many items are allowed in the collection
How does the definition of a stack differ from that of an array?
The definition provides for the insertion and deletion of items. It is a dynamic constantly changing structure
Underflow
The result of an illegal attempt to pop or access an item from an empty stack
What is the most important attribute of a stack?
The last element inserted is the first element deleted
Which way is up?
The question we must answer to designate the top - where items can be added or deleted
Before applying the pop operator to a stack, we must ensure...
The stack is not empty
Deletion can only be made from...?
The top
Where is the only one place on the stack where a new item can be placed
The top
Pushdown List
What a stack is sometimes referred to because of the push operation which adds elements to a stack