Professional Documents
Culture Documents
Chapter 7
Stacks
Objectives
• Top of stack
– Index of last element added to the stack
• Stack element accessed only through the top
– Problem: array is a random access data structure
– Solution: use another variable (stackTop)
• Keeps track of the top position of the array
• Stack full
– If stackTop is equal to maxStackSize
• Definition of function isFullStack
• Arithmetic notations
– Infix notation: operator between operands
– Prefix (Polish) notation: operator precedes operands
– Reverse Polish notation: operator follows operands
Note: A pointer to each node in the linked list is saved in the stack. The top
element of the stack contains a pointer to the last node in the list, and so on.
Output:
Note: A pointer to each node in the linked list is saved in the stack. The top
element of the stack contains a pointer to the last node in the list, and so on.