Skip to content

Lists, stacks and queues

Stacks

Lessons on this topic

Intermediate · 30 minYou are hereRead

Stacks

A stack adds and removes items only at its top, last in, first out. Built here on an array with a top index, then on linked nodes; every operation takes the same few steps.

Intermediate · 20 minYou are hereRead

Matching brackets

Brackets match when every closer meets the most recent unmatched opener of its kind, which is exactly the top of a stack. One pass, three ways to fail.

Intermediate · 25 minYou are hereRead

Infix to postfix

Rewriting (8 - 2) * 3 + 4 as 8 2 - 3 * 4 + removes the need for brackets and precedence, and operators waiting on a stack do the rewriting.

Intermediate · 20 minYou are hereRead

Evaluating postfix

A postfix expression is worked out in one pass: push the numbers, and let each operator pop two and push their result. No brackets, no precedence.

Phasorium

Account

Sign inWith Google, GitHub or your email

Subjects

Site

Look