- Forward


Examples of Stacks and Queues
In Computing and Elsewhere


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Real-World Examples
Back SMYC Forward
  • Stacks:
    • Drink Shelves at Convenience Stores
    • Trucks/Containers/Boxcars
  • Queues:
    • "Checkout" Lines
    • Toll Booths
Computing Examples
Back SMYC Forward
  • Stacks:
    • Activation Records/Call Stack
    • Undo Stack
  • Queues:
    • Process/Thread Queue
    • Event Queue
    • Print Queue
Evaluating Postfix Expressions
Back SMYC Forward
  • Different Notations:
    • Infix: 5 + 3
    • Prefix: + 5 3
    • Postfix: 5 3 +
  • Complex Postfix Expressions:
    1. Choose any group: operand1 operand2 operator
    2. Evaluate that group
    3. Replace the group with its evaluation
    4. Repeat
Evaluating Postfix Expressions (cont.)
Back SMYC Forward
3 4 * 8 7 3 - / / 4 +
Evaluating Postfix Expressions Using a Stack
Back SMYC Forward
while (moreTokens) { token = nextToken() if (token isa number) { push(token) } else { operand2 = pop() operand1 = pop() result = operand1 token operand2 push(result) } } answer = pop() return answer
There's Always More to Learn
Back -