Stack
Wikipedia on stacks.
Similarly, the Linked List, a stack is an abstract data type. It is LIFO, or Last In First Out. Each node holds data and a pointer to the next node.
Visualization
|42|
|
|60|
|
|99|
|
|3|
|
None
The main operations available to the Stack are push and pop.
- Pop should remove the top node and return it.
- Push should add to the top of the stack.
Methods
Create your datatypes and create the following methods:
-
push - adds to the stack
-
pop - removes from the top of the stack
-
peek - Find the item at the top of the stack
-
empty - Is the stack empty?
Additional Methods
In the wikipedia article, read under the title "Hardware Stacks". Emulating a hardware stack, add the operations it lists to your class. This is open ended and implementation is up to you.