💡 In the RPN calculator: the input expression is processed like a queue (left to right). The operands are managed on a stack (push numbers, pop to compute).
2
How RPN uses both structures
Reverse Polish Notation puts operators after their operands. 3 4 + 2 * means (3 + 4) × 2 = 14.
The algorithm has two phases:
// Phase 1: tokenize input into a Queue (left to right)
Queue<String> tokenQueue = new LinkedList<>();
for (String token : expression.split(" ")) {
tokenQueue.enqueue(token); // FIFO — preserve left-to-right order
}
// Phase 2: evaluate using a Stack
Stack<Double> operandStack = new Stack<>();
while (!tokenQueue.isEmpty()) {
String token = tokenQueue.dequeue(); // pull next tokenif (isNumber(token)) {
operandStack.push(Double.parseDouble(token)); // push operand
} else {
// operator: pop TWO operands, compute, push resultdouble b = operandStack.pop(); // right operand (popped first)double a = operandStack.pop(); // left operand
operandStack.push(compute(a, token, b));
}
}
// final answer sits alone on the stackreturn operandStack.pop();
3
Step-through visualizer
Expression: 3 4 + 2 * → expected result: 14
Token queue (input — dequeued left to right)
Operand stack (top = right)
Press Next Step to begin
4
Live RPN calculator
+100 XP on first correct eval
Type any RPN expression and evaluate it. Separate tokens with spaces.
In the code above, when we hit an operator we do b = pop() then a = pop(). Why does order matter?
🔗
How this maps to AutoTriage
DS2 → Capstone
The same stack/queue thinking appears directly in the AutoTriage backend:
Queue pattern
ActivityRepository.findAllSince() returns events in insertion order — FIFO, oldest first. DigestGenerator processes them left to right just like the token queue.
Stack pattern
The VSCode extension uses a Set<String> to accumulate files (like pushing onto a stack), then drains it all at once when Generate is called — analogous to popping the final result.
This is the answer to "how do your DS2 objectives map to your project?" — point at these two classes and explain the analogy.
🏆
Stack & Queue — complete!
★ 0 / 300 XP · You're ready to demo this to Mortensen.