Data Structures: Stack, Queue, and Deque

Stack Imagine organizing a closet by placing winter clothes first, then summer clothes on top. When summer arrives, you grab the summer clothes first from the top without disturbing the items below. A stack is a container that allows storing, accessing, and removing elements exclusively from one end called the top. This constraint means the ele ...

Posted on Mon, 27 Jul 2026 16:10:14 +0000 by sunnyk

Zigzag Level Order Traversal of Binary Tree

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its zigzag level order traversal as: [ [3], [20,9], [15,7] ] Appr ...

Posted on Mon, 27 Jul 2026 16:05:55 +0000 by Hypnos

Implementing Nested DataSource Context Holder with ThreadLocal Deque

DataSource Context Holder Implementation Based on Deque public class DataSourceContextManager { // Using ThreadLocal<Deque> to support nested data sources private static final ThreadLocal<Deque<DataSourceEnum>> CONTEXT_HOLDER = ThreadLocal.withInitial(ArrayDeque::new); /** * Push data source type ...

Posted on Thu, 09 Jul 2026 16:50:33 +0000 by dodgei

Solutions to AtCoder ABC 066

Problem A - Sum of Two Smallest Numbers Statement: Given three integers, output the sum of the two smallest values. Solution: Subtract the maximum value from the total sum. int a, b, c; cin >> a >> b >> c; cout << a + b + c - max({a, b, c}) << endl; Problem B - Finding the Longest Even Prefix Statement: A string i ...

Posted on Sun, 10 May 2026 03:20:54 +0000 by mynameisbob

Understanding STL Container Adapters: stack and queue

The essence of a container adapter lies in the principle of reuse. Instead of implementing storage structures from scratch, these adapters leverage existing containers to handle data storage while exposing only the interfaces relevant to their specific access patterns. This adapter pattern represents a fundamental design philosophy in software ...

Posted on Sat, 09 May 2026 06:42:40 +0000 by mgilbert

Algorithmic Patterns with Stacks, Monotonic Deques, and Priority Queues in C++

Evaluating Reverse Polish Notation Reverse Polish Notation (RPN) eliminates the need for parentheses by placing operators after their operands. A stack-based approach efficiently processes tokens in a single pass. class Solution { public: int evalRPN(vector<string>& expr) { stack<int> eval_stack; for (const a ...

Posted on Sat, 09 May 2026 00:38:32 +0000 by tazgalsinh