Linked List, Queue, and Stack in C++
Linked List, Queue, and Stack in C++ Interview with follow-up questions
1. Can you explain the differences between a linked list, a queue, and a stack in C++?
A linked list, a queue, and a stack are three fundamental data structures. They differ in their access patterns, ordering constraints, and typical use cases.
Linked List: A sequence of nodes where each node holds a value and a pointer to the next node (and optionally the previous node in a doubly-linked list). It imposes no particular ordering constraint — you can insert or delete at any position in O(1) if you have a pointer to that node, but random access by index is O(n). The STL provides
std::list(doubly-linked) andstd::forward_list(singly-linked, lower overhead). Use a linked list when you need frequent insertions or deletions in the middle of a sequence and do not need random access.Queue: A restricted-access container that enforces First-In-First-Out (FIFO) order. Elements enter at the back (
push/enqueue) and leave from the front (pop/dequeue). The STL providesstd::queue, which is a container adaptor backed bystd::dequeby default. Random access and iteration are not supported — only the front and back are visible. Use a queue for task scheduling, BFS traversal, producer-consumer pipelines, and any scenario requiring ordered processing.Stack: A restricted-access container that enforces Last-In-First-Out (LIFO) order. Elements are pushed and popped from the same end (the top). The STL provides
std::stack, a container adaptor backed bystd::dequeby default. Only the top element is accessible. Use a stack for function call management, expression parsing, DFS traversal, undo/redo histories, and backtracking algorithms.
Comparison at a glance
| Property | Linked List | Queue | Stack |
|---|---|---|---|
| Ordering | None (position-based) | FIFO | LIFO |
| Insert | Any position O(1) | Back only O(1) | Top only O(1) |
| Remove | Any position O(1) | Front only O(1) | Top only O(1) |
| STL type | std::list / std::forward_list |
std::queue |
std::stack |
| Random access | O(n) | Not supported | Not supported |
Key distinction: A queue and a stack are interface constraints on top of an underlying storage structure (which may itself be a linked list or a deque). A linked list is a storage structure with its own API. Both std::queue and std::stack can be backed by std::list if you specify it as the template argument.
Follow-up 1
How would you implement a queue using two stacks in C++?
To implement a queue using two stacks in C++, you can use the following approach:
#include
class Queue {
private:
std::stack stack1;
std::stack stack2;
public:
void enqueue(int value) {
stack1.push(value);
}
int dequeue() {
if (stack2.empty()) {
while (!stack1.empty()) {
stack2.push(stack1.top());
stack1.pop();
}
}
int value = stack2.top();
stack2.pop();
return value;
}
};
int main() {
Queue queue;
queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
std::cout << queue.dequeue() << std::endl; // Output: 1
std::cout << queue.dequeue() << std::endl; // Output: 2
std::cout << queue.dequeue() << std::endl; // Output: 3
return 0;
}
In this implementation, the enqueue operation is performed by pushing elements onto stack1. The dequeue operation is performed by transferring elements from stack1 to stack2 in reverse order, and then popping the top element from stack2.
Follow-up 2
Can you describe a scenario where a linked list would be more beneficial to use than a queue or a stack?
A scenario where a linked list would be more beneficial to use than a queue or a stack is when frequent insertions and deletions at arbitrary positions in the collection are required. Linked lists provide efficient insertion and deletion operations at any position, as they only require updating the references between nodes. In contrast, queues and stacks have specific insertion and deletion points (front and back for queues, top for stacks) and do not support efficient operations at arbitrary positions. Therefore, if the order of elements is not important and random access is not required, a linked list can be a better choice.
Follow-up 3
What are the time complexities of insertion, deletion and access operations in these data structures?
The time complexities of insertion, deletion, and access operations in linked lists, queues, and stacks are as follows:
Linked List:
- Insertion at the beginning: O(1)
- Insertion at the end: O(1) (with a reference to the tail)
- Insertion at an arbitrary position: O(n)
- Deletion at the beginning: O(1)
- Deletion at the end: O(1) (with a reference to the tail)
- Deletion at an arbitrary position: O(n)
- Access by index: O(n)
Queue:
- Enqueue (insertion at the back): O(1)
- Dequeue (deletion from the front): O(1)
- Access to other elements: O(n)
Stack:
- Push (insertion at the top): O(1)
- Pop (deletion from the top): O(1)
- Access to other elements: O(n)
It's important to note that these time complexities are based on the assumption that the data structures are implemented efficiently, using appropriate data structures and algorithms.
2. How would you implement a linked list in C++?
A singly-linked list is built from nodes, each holding a value and a pointer to the next node. The modern C++ version uses smart pointers to manage node lifetime automatically and avoids raw new/delete.
Node and list definition
#include
#include
#include
struct Node {
int data;
std::unique_ptr next;
explicit Node(int val) : data{val}, next{nullptr} {}
};
class LinkedList {
public:
LinkedList() = default;
// Disable copy; enable move
LinkedList(const LinkedList&) = delete;
LinkedList& operator=(const LinkedList&) = delete;
LinkedList(LinkedList&&) = default;
LinkedList& operator=(LinkedList&&) = default;
void push_front(int val) {
auto node = std::make_unique(val);
node->next = std::move(head_);
head_ = std::move(node);
}
void push_back(int val) {
auto node = std::make_unique(val);
if (!head_) {
head_ = std::move(node);
return;
}
Node* cur = head_.get();
while (cur->next) cur = cur->next.get();
cur->next = std::move(node);
}
void pop_front() {
if (head_) head_ = std::move(head_->next);
}
int front() const { return head_->data; }
bool empty() const { return head_ == nullptr; }
void print() const {
for (Node* cur = head_.get(); cur; cur = cur->next.get())
std::cout << cur->data << ' ';
std::cout << '\n';
}
private:
std::unique_ptr head_;
};
int main() {
LinkedList list;
list.push_back(1);
list.push_back(2);
list.push_back(3);
list.print(); // 1 2 3
list.pop_front();
list.print(); // 2 3
return 0;
}
Key design decisions to mention in an interview
std::unique_ptrfor nodes — ownership is clear: each node owns the next. When a node is destroyed, it recursively destroys its successor. No manualdeleteis needed.push_backis O(n) — a tail pointer can reduce this to O(1) at the cost of extra complexity.- Deep recursion risk — the destructor chain for a very long list can overflow the stack. An iterative destructor (or using
std::listfrom the STL) avoids this.
Prefer std::list or std::forward_list in production
For real code, use the STL containers — they are well-tested, handle all edge cases, and support iterators and range-based for. Implement a linked list from scratch primarily as a learning or interview exercise to demonstrate understanding of pointer/ownership semantics.
Follow-up 1
What are the advantages and disadvantages of using a linked list?
Advantages of using a linked list:
- Dynamic size: Linked lists can grow or shrink dynamically, allowing for efficient memory usage.
- Insertion and deletion: Insertion and deletion operations can be performed in constant time, as long as the position of the element is known.
Disadvantages of using a linked list:
- Random access: Linked lists do not support random access to elements, meaning that accessing an element at a specific index requires traversing the list from the beginning.
- Extra memory: Linked lists require extra memory to store the pointers/references to the next nodes, which can be inefficient for small data types.
- Sequential access: Sequentially accessing elements in a linked list can be slower compared to arrays or vectors due to the lack of cache locality.
Follow-up 2
How would you implement a doubly linked list?
To implement a doubly linked list in C++, you can modify the Node class from the previous example to include a pointer to the previous node. Here's an example implementation:
#include
class Node {
public:
int data;
Node* next;
Node* prev;
};
class DoublyLinkedList {
public:
Node* head;
DoublyLinkedList() {
head = nullptr;
}
void insert(int value) {
Node* newNode = new Node;
newNode->data = value;
newNode->next = nullptr;
newNode->prev = nullptr;
if (head == nullptr) {
head = newNode;
} else {
Node* current = head;
while (current->next != nullptr) {
current = current->next;
}
current->next = newNode;
newNode->prev = current;
}
}
void display() {
Node* current = head;
while (current != nullptr) {
std::cout << current->data << " ";
current = current->next;
}
std::cout << std::endl;
}
};
int main() {
DoublyLinkedList list;
list.insert(1);
list.insert(2);
list.insert(3);
list.display();
return 0;
}
In this implementation, the Node class has an additional prev pointer that points to the previous node in the list. The insert function is modified to update the prev pointer of the new node when inserting it at the end of the list.
Follow-up 3
Can you write a function to reverse a linked list in C++?
Sure! Here's an example function to reverse a linked list in C++:
void reverseLinkedList(LinkedList& list) {
Node* prev = nullptr;
Node* current = list.head;
Node* next = nullptr;
while (current != nullptr) {
next = current->next;
current->next = prev;
prev = current;
current = next;
}
list.head = prev;
}
This function uses three pointers (prev, current, and next) to reverse the links between the nodes in the linked list. It starts by initializing prev to nullptr, current to the head of the list, and next to nullptr. Then, it iterates through the list, updating the links and moving the pointers until the end of the list is reached. Finally, it updates the head of the list to the last node, effectively reversing the list.
3. What are the applications of queues and stacks in C++?
Queues and stacks appear throughout systems and algorithm design. Understanding their applications helps interviewers assess whether you can recognize the right abstraction for a problem.
Applications of queues
- Breadth-first search (BFS): A queue is the backbone of BFS — nodes are enqueued as they are discovered and processed in FIFO order, guaranteeing level-by-level traversal in graphs and trees.
- Task scheduling / work queues: Operating systems and thread pools use queues to dispatch jobs in the order they arrive (e.g.,
std::queuein a producer-consumer pattern withstd::mutexandstd::condition_variable). - Print spooling and I/O buffering: Requests are queued and served in order; a slow device does not block the producer.
- Message passing / event systems: Asynchronous message queues (e.g., in game loops or UI event loops) buffer events so they are handled one at a time.
- Level-order tree traversal: Printing or processing a tree level by level uses a queue to manage the current frontier.
- Network packet buffering: Routers queue packets to handle bursts and smooth traffic.
Applications of stacks
- Function call stack: The runtime manages function calls, local variables, and return addresses using a stack — each call pushes a frame, each return pops it.
- Expression parsing and evaluation: A stack converts infix expressions to postfix (Shunting-yard algorithm) and evaluates them; compilers, calculators, and spreadsheet engines use this.
- Depth-first search (DFS): DFS can be implemented iteratively using an explicit stack instead of recursion, avoiding stack-overflow risks on deep graphs.
- Undo / redo: Text editors and graphics tools maintain a stack of reversible commands;
undopops and reverses,redouses a second stack. - Balanced-bracket checking: Push opening brackets, pop and match on closing brackets — a common interview problem.
- Backtracking algorithms: Maze solving, Sudoku, and constraint-satisfaction problems push partial solutions and backtrack by popping when a dead end is reached.
- Browser history navigation: Back/forward navigation uses two stacks — the back history and the forward history.
STL types used in practice
#include
#include
std::queue q; // FIFO; backed by std::deque by default
std::stack s; // LIFO; backed by std::deque by default
// For priority scheduling, prefer:
std::priority_queue pq; // max-heap by default
Follow-up 1
Can you explain how a stack can be used for checking balanced parentheses?
Yes, a stack can be used to check whether a given expression has balanced parentheses. The algorithm works as follows:
- Initialize an empty stack.
- Traverse the expression from left to right.
- If the current character is an opening parenthesis (e.g., '(', '{', '['), push it onto the stack.
- If the current character is a closing parenthesis (e.g., ')', '}', ']'), check if the stack is empty. If it is, return false as there is no corresponding opening parenthesis. If the stack is not empty, pop the top element from the stack and check if it is the corresponding opening parenthesis. If it is not, return false. If it is, continue to the next character.
- After traversing the entire expression, check if the stack is empty. If it is, return true as all parentheses are balanced. If it is not, return false as there are unmatched opening parentheses.
Here is an example implementation in C++:
#include
#include
#include
bool isBalanced(const std::string& expression) {
std::stack parenthesesStack;
for (char c : expression) {
if (c == '(' || c == '{' || c == '[') {
parenthesesStack.push(c);
}
else if (c == ')' || c == '}' || c == ']') {
if (parenthesesStack.empty()) {
return false;
}
char top = parenthesesStack.top();
parenthesesStack.pop();
if ((c == ')' && top != '(') || (c == '}' && top != '{') || (c == ']' && top != '[')) {
return false;
}
}
}
return parenthesesStack.empty();
}
int main() {
std::string expression = "((a + b) * (c - d))";
if (isBalanced(expression)) {
std::cout << "The expression has balanced parentheses." << std::endl;
}
else {
std::cout << "The expression does not have balanced parentheses." << std::endl;
}
return 0;
}
Follow-up 2
How would you use a queue in a breadth-first search algorithm?
In a breadth-first search (BFS) algorithm, a queue is used to keep track of the nodes that need to be visited. The algorithm works as follows:
- Initialize an empty queue and a boolean array to keep track of visited nodes.
- Enqueue the starting node into the queue and mark it as visited.
- Repeat the following steps until the queue is empty:
- Dequeue a node from the front of the queue.
- Process the node (e.g., print its value or perform any desired operation).
- Enqueue all the unvisited neighbors of the node into the queue and mark them as visited.
- The BFS algorithm is complete when all reachable nodes have been visited.
Here is an example implementation in C++:
#include
#include
#include
void breadthFirstSearch(const std::vector>& graph, int startNode) {
int numNodes = graph.size();
std::vector visited(numNodes, false);
std::queue nodeQueue;
nodeQueue.push(startNode);
visited[startNode] = true;
while (!nodeQueue.empty()) {
int currentNode = nodeQueue.front();
nodeQueue.pop();
std::cout << "Visiting node: " << currentNode << std::endl;
for (int neighbor : graph[currentNode]) {
if (!visited[neighbor]) {
nodeQueue.push(neighbor);
visited[neighbor] = true;
}
}
}
}
int main() {
std::vector> graph = {
{1, 2},
{0, 2, 3},
{0, 1, 3},
{1, 2}
};
int startNode = 0;
breadthFirstSearch(graph, startNode);
return 0;
}
Follow-up 3
Can you describe a real-world scenario where a stack or queue data structure would be useful?
Sure! Here is an example scenario for both a stack and a queue:
Stack: A stack data structure can be useful in a web browser's back button functionality. When a user visits different web pages, the URLs of the visited pages can be stored in a stack. When the user clicks the back button, the most recently visited URL is popped from the stack and the user is redirected to that page.
Queue: A queue data structure can be useful in a print spooler system. When multiple users send print requests to a printer, the requests can be stored in a queue. The printer processes the requests in the order they were added to the queue (FIFO), ensuring fairness and preventing any user from monopolizing the printer.
Both stack and queue data structures have numerous other real-world applications, but these examples illustrate their usefulness in managing and processing data in specific scenarios.
4. How would you implement a stack using a linked list in C++?
A stack can be implemented using a linked list by treating the head of the list as the top of the stack. Push prepends a new node, and pop removes the head — both operations are O(1). Using std::unique_ptr for node ownership eliminates manual delete.
#include
#include
#include
class Stack {
struct Node {
int data;
std::unique_ptr next;
Node(int val, std::unique_ptr n)
: data{val}, next{std::move(n)} {}
};
std::unique_ptr top_;
std::size_t size_{0};
public:
void push(int val) {
top_ = std::make_unique(val, std::move(top_));
++size_;
}
void pop() {
if (empty()) throw std::underflow_error{"Stack is empty"};
top_ = std::move(top_->next);
--size_;
}
int peek() const {
if (empty()) throw std::underflow_error{"Stack is empty"};
return top_->data;
}
bool empty() const { return top_ == nullptr; }
std::size_t size() const { return size_; }
};
int main() {
Stack s;
s.push(1);
s.push(2);
s.push(3);
std::cout << s.peek() << '\n'; // 3
s.pop();
std::cout << s.peek() << '\n'; // 2
s.pop();
std::cout << s.peek() << '\n'; // 1
s.pop();
try {
s.pop(); // throws std::underflow_error
} catch (const std::underflow_error& e) {
std::cout << e.what() << '\n';
}
return 0;
}
Key points to mention in an interview
std::unique_ptrownership chain: Each node owns the next via aunique_ptr. When the top node is destroyed (by moving itsnextintotop_), the old head node is automatically deleted — no rawdeleteanywhere.- Push is O(1): Prepending to a linked list is constant time regardless of list length.
- Pop is O(1): Moving the
unique_ptrto the next node destroys the old head in O(1). - No capacity limit: Unlike an array-based stack, this implementation never needs to reallocate.
- Exception safety: Throwing
std::underflow_erroris cleaner than returning a sentinel like-1, which is ambiguous when-1is a valid value. - Deep-destruction risk: Popping all elements one by one is safe, but the destructor of a very long stack will recursively destroy nodes, potentially overflowing the call stack. An iterative destructor handles this edge case.
In production, prefer std::stack
#include
std::stack s; // backed by std::deque; well-tested and efficient
Implement a linked-list stack from scratch primarily to demonstrate ownership and pointer semantics in an interview.
Follow-up 1
What are the advantages of implementing a stack using a linked list?
There are several advantages of implementing a stack using a linked list:
- Dynamic size: Unlike an array-based implementation, a linked list-based implementation allows the stack to grow and shrink dynamically without requiring a fixed size.
- Efficient insertion and deletion: Insertion and deletion operations can be performed in constant time O(1) at the top of the stack, as they only involve updating the top pointer and creating or deleting a node.
- No overflow or underflow: Since a linked list can dynamically allocate memory, there is no fixed size limit for the stack, preventing overflow or underflow conditions.
- Easy implementation: Implementing a stack using a linked list is relatively simple and requires fewer lines of code compared to an array-based implementation.
Follow-up 2
Can you write a function to find the minimum element in a stack in O(1) time?
Yes, it is possible to find the minimum element in a stack in O(1) time by using an additional stack to keep track of the minimum values. Here's an example implementation in C++:
#include
#include
using namespace std;
class MinStack {
private:
stack mainStack;
stack minStack;
public:
void push(int value) {
mainStack.push(value);
if (minStack.empty() || value <= minStack.top()) {
minStack.push(value);
}
}
void pop() {
if (mainStack.empty()) {
cout << "Stack is empty. Cannot pop." << endl;
return;
}
if (mainStack.top() == minStack.top()) {
minStack.pop();
}
mainStack.pop();
}
int getMin() {
if (minStack.empty()) {
cout << "Stack is empty." << endl;
return -1;
}
return minStack.top();
}
};
int main() {
MinStack stack;
stack.push(3);
stack.push(2);
stack.push(5);
stack.push(1);
cout << stack.getMin() << endl; // Output: 1
stack.pop();
cout << stack.getMin() << endl; // Output: 2
stack.pop();
cout << stack.getMin() << endl; // Output: 2
return 0;
}
Follow-up 3
How would you handle underflow and overflow conditions in a stack?
In a stack, underflow occurs when trying to pop an element from an empty stack, and overflow occurs when trying to push an element into a full stack. Here's how you can handle these conditions:
Underflow: When popping an element from an empty stack, you can check if the stack is empty before performing the pop operation. If the stack is empty, you can display an error message or throw an exception to indicate that the stack is empty and popping is not possible.
Overflow: In a linked list-based implementation, the stack can dynamically allocate memory, so overflow is less likely to occur. However, if you have a fixed-size array-based implementation, you can check if the stack is full before performing the push operation. If the stack is full, you can display an error message or throw an exception to indicate that the stack is full and pushing is not possible.
5. Can you explain how a circular queue works in C++?
A circular queue (also called a ring buffer or circular buffer) is a fixed-capacity queue implemented over an array where the front and rear indices wrap around to the beginning when they reach the end. This eliminates the "false full" problem of a naive array-based queue, where dequeuing from the front leaves unused space at the beginning that can never be reclaimed without shifting elements.
How it works
- Two indices track the positions:
front(next element to dequeue) andrear(where the next enqueue will write). - After each operation the index advances as
index = (index + 1) % capacity, wrapping back to 0 when it reaches the end of the array. - The queue is full when
(rear + 1) % capacity == front(one slot is intentionally left empty to distinguish full from empty). - The queue is empty when
front == rear.
#include
#include
class CircularQueue {
public:
explicit CircularQueue(int cap)
: buf_(cap + 1), cap_(cap + 1) {} // extra slot for full/empty distinction
void enqueue(int val) {
if (full()) throw std::overflow_error{"Queue is full"};
buf_[rear_] = val;
rear_ = (rear_ + 1) % cap_;
}
int dequeue() {
if (empty()) throw std::underflow_error{"Queue is empty"};
int val = buf_[front_];
front_ = (front_ + 1) % cap_;
return val;
}
int front() const {
if (empty()) throw std::underflow_error{"Queue is empty"};
return buf_[front_];
}
bool empty() const { return front_ == rear_; }
bool full() const { return (rear_ + 1) % cap_ == front_; }
int size() const {
return (rear_ - front_ + cap_) % cap_;
}
private:
std::vector buf_;
int cap_;
int front_{0};
int rear_{0};
};
Complexity
- Enqueue: O(1)
- Dequeue: O(1)
- Space: O(capacity) — fixed allocation, no dynamic resizing
Advantages over a plain queue
- Memory is reused in place — no shifting of elements needed.
- All operations are O(1) and allocation-free after construction.
- Ideal for bounded, high-throughput scenarios: audio/video ring buffers, OS kernel I/O buffers, lock-free SPSC queues in concurrent systems.
STL note
std::queue backed by std::deque handles growing queues well in general code. For fixed-size, zero-allocation ring buffers (common in embedded systems and real-time audio), a circular queue is the right structure. The C++ standard library does not provide a circular buffer directly, but boost::circular_buffer is a widely used alternative.
Follow-up 1
What are the advantages of a circular queue over a simple queue?
There are several advantages of a circular queue over a simple queue:
Efficient memory utilization: In a circular queue, the elements are stored in a fixed-size array, and the front and rear pointers wrap around the array. This allows the queue to efficiently utilize the available memory.
Constant time complexity for enqueue and dequeue operations: In a circular queue, the front and rear pointers are incremented or decremented in a circular manner. This ensures that the enqueue and dequeue operations have a constant time complexity of O(1), regardless of the size of the queue.
Ability to reuse empty spaces: In a circular queue, when elements are dequeued, the empty spaces can be reused for future enqueue operations. This reduces the need for resizing the queue and improves the overall efficiency.
Follow-up 2
How would you implement a circular queue using an array?
To implement a circular queue using an array, you would need to define an array of a fixed size, and two pointers: front and rear. The front pointer points to the first element in the queue, and the rear pointer points to the last element in the queue. Initially, both pointers are set to -1 to indicate an empty queue.
Here is an example implementation of a circular queue using an array in C++:
#define MAX_SIZE 10
class CircularQueue {
int arr[MAX_SIZE];
int front;
int rear;
public:
CircularQueue() {
front = -1;
rear = -1;
}
bool isEmpty() {
return (front == -1 && rear == -1);
}
bool isFull() {
return (front == (rear + 1) % MAX_SIZE);
}
void enqueue(int data) {
if (isFull()) {
cout << "Queue is full. Cannot enqueue." << endl;
return;
}
else if (isEmpty()) {
front = 0;
rear = 0;
}
else {
rear = (rear + 1) % MAX_SIZE;
}
arr[rear] = data;
}
void dequeue() {
if (isEmpty()) {
cout << "Queue is empty. Cannot dequeue." << endl;
return;
}
else if (front == rear) {
front = -1;
rear = -1;
}
else {
front = (front + 1) % MAX_SIZE;
}
}
int getFront() {
if (isEmpty()) {
cout << "Queue is empty." << endl;
return -1;
}
return arr[front];
}
};
Follow-up 3
Can you write a function to insert and delete elements in a circular queue?
Certainly! Here is an example implementation of functions to insert and delete elements in a circular queue:
#define MAX_SIZE 10
class CircularQueue {
int arr[MAX_SIZE];
int front;
int rear;
public:
CircularQueue() {
front = -1;
rear = -1;
}
bool isEmpty() {
return (front == -1 && rear == -1);
}
bool isFull() {
return (front == (rear + 1) % MAX_SIZE);
}
void enqueue(int data) {
if (isFull()) {
cout << "Queue is full. Cannot enqueue." << endl;
return;
}
else if (isEmpty()) {
front = 0;
rear = 0;
}
else {
rear = (rear + 1) % MAX_SIZE;
}
arr[rear] = data;
}
void dequeue() {
if (isEmpty()) {
cout << "Queue is empty. Cannot dequeue." << endl;
return;
}
else if (front == rear) {
front = -1;
rear = -1;
}
else {
front = (front + 1) % MAX_SIZE;
}
}
int getFront() {
if (isEmpty()) {
cout << "Queue is empty." << endl;
return -1;
}
return arr[front];
}
};
int main() {
CircularQueue queue;
queue.enqueue(10);
queue.enqueue(20);
queue.enqueue(30);
cout << "Front element: " << queue.getFront() << endl;
queue.dequeue();
cout << "Front element after dequeue: " << queue.getFront() << endl;
return 0;
}
Live mock interview
Mock interview: Linked List, Queue, and Stack in C++
- Read your scene and goals
- Talk it out; goals tick off live
- Get a score and stronger lines
Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.