Lecture Objectives for Stack Lecture
At the end of today's class you should
KNOW:
- That a stack is a LIFO (last-in-first-out) data structure
- That a stack is a useful data structure to use when items need to
be processed in reverse order
- What information is stored in a stack frame (for function calls)
- That when a function is called, a stack frame is pushed on the runtime stack
- That when a function returns, a stack frame is popped off the runtime stack
BE ABLE TO:
- implement the stack operations (push, pop, isEmpty) using a linked list
- explain how the runtime stack is affected as a program makes function calls
Sample Exam Question:
Implement a function that satisfies the following pre- and post-conditions.
You may assume that struct listNode is defined as
struct listNode{
int data;
struct listNode *next;
};
// PRE: top is a pointer to a pointer that points to the top item in
// a non-empty stack
// POST: the function returns the top item of the stack, and the
// item has been popped off the stack
int pop (struct listNode **top);