(Latest Revision: 11/11/2003)
Stack Information for CS2
- Definition of the stack data type
- Organization -- Last-In, First-Out
- Elements -- any given homogeneous set
- Operations
- constructor(s)
- destructor(s)
- bool StackIsEmpty()
- void Push(stackItemType NewItem, bool& Success)
- void Pop(bool& Success)
- void Pop(stackItemType& StackTop, bool& Success)
- void GetStackTop(stackItemType& StackTop, bool& Success)
- Applications of the stack data type
- Evaluating postfix expressions
- "Towers of Hanoi" puzzle program
- depth-first search
- Implementations of the stack data type
- array-based implementation
- pointer-based implementation
- "as-a-list" implementations
- Pro's and Con's of different implementations of the stack ADT.
- array-based implementation
- PRO: simple code
- PRO: all operations are O(1) (compare with "list classes")
- CON: static allocation
- pointer-based implementation
- PRO: dynamic memory allocation
- PRO: most operations are O(1) (compare with "list classes")
- CON: destructor is O(N)
- CON: extra memory required for each element.
- "as-a-list" implementations
- PRO: extremely easy to program
- PRO: if done a certain way, can be as efficient as coding
"from scratch."
- PRO: can be done with an array-based list or with a
pointer-based list.
- CON: There is extra function-call overhead.
- CON: can be very inefficient if not done carefully -- the
example code is inefficient if the list has the array
implementation, and is efficient if the list has the
linked implementation.