JMU
Examples of Stacks and Queues
In Computing and Elsewhere


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Real-World Examples
Computing Examples
Evaluating Postfix Expressions
Evaluating Postfix Expressions (cont.)
3 4 * 8 7 3 - / / 4 +
Evaluating Postfix Expressions Using a Stack
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