Implementing a Queue

Introduction

A queue is an abstract data type defined by its behavior: elements enter at the rear and leave from the front, in first-in-first-out order. Knowing that behavior is not the same as being able to build it. In this topic you move from the concept to the code, implementing the queue two different ways — on top of a fixed-size array and on top of a linked list — and seeing exactly what each choice costs you.

The array-based version is usually the first one students write, and it is also the one that exposes the most interesting problems. Where do front and rear pointers start? What happens when rear reaches the end of the array but space has been freed at the front? How do you distinguish an empty queue from a full one? The linked list version avoids the fixed-capacity problem but introduces pointer bookkeeping of its own, especially when the queue becomes empty and both head and tail must be reset.

As you watch, keep a running list of three things: the exact conditions that signal overflow and underflow, the pointer updates performed by enqueue and dequeue, and the time and space cost of each operation. You should finish this topic able to argue for one implementation over the other given a specific scenario, not just recite that both are O(1) for the core operations.

Video 1: Lec-50: Implementation of Queue using Array | Enqueue() in Queue | Data Structure #gatesmashers

Gate Smashers · 13:15 · 143,376 views · 3y ago · captions — Watch on YouTube

About this video

This lecture walks through building a queue on top of an array, focusing on the enqueue operation and the front and rear index variables that track the queue's boundaries. Based on its title and placement in a sequenced data structures series, it is likely to cover the initial values of the pointers, the overflow condition when rear reaches the end of the array, and the step-by-step code for inserting an element.

Why this video

Gate Smashers produces exam-oriented data structures lectures with careful step-by-step tracing, which makes it a strong fit for the array-based implementation and edge-case handling subtopics where small index errors matter most.

Video 2: Lec-51: Implementation of Queue using Linked List | Enqueue() in Queue | Data Structure

Gate Smashers · 11:35 · 103,436 views · 3y ago · captions — Watch on YouTube

About this video

The follow-up lecture in the same series implements the queue using a linked list, with enqueue highlighted in the title. Expect coverage of node creation, maintaining front and rear pointers, the special case of inserting into an empty queue, and how dynamic allocation removes the fixed-capacity limit of the array version.

Why this video

Watching this immediately after the array lecture gives you the same instructor, notation, and worked style applied to the second implementation, which makes the structural trade-offs between the two approaches easier to see directly.

Video 3: Queues Explained and Implemented with Arrays and LinkedLists in Java | Data Structures | Geekific

Geekific · 12:01 · 3,165 views · 5y ago · captions — Watch on YouTube

About this video

Geekific explains the queue ADT and then implements it both ways in Java, so array-based and linked-list-based versions appear side by side in a single video. The description points to an accompanying GitHub repository, so the full source for the core operations is available to read and run alongside the explanation.

Why this video

Its dual-implementation format directly serves the trade-offs subtopic, and seeing real compilable Java code bridges the gap between the pseudocode in the lectures and the code you will write for this course.

How These Videos Support the Learning Outcomes

Together these videos carry you from the FIFO definition into working code (MO1, MO2): the first two lectures build the array-based and linked list-based queues separately, with explicit attention to pointer initialization, overflow and underflow conditions, and the empty-queue edge case, while the Geekific video shows both implementations in compilable Java you can study and extend. Presenting the two approaches in parallel also sets up the comparison required by MO3, since you can weigh fixed capacity and index arithmetic against per-node memory overhead and pointer maintenance while both implementations are fresh. The implementation-level detail here reinforces the access-point reasoning — insert at rear, remove at front — that you will contrast with stack behavior when addressing MO4 and MO5.

About These Videos

These videos were chosen from YouTube on October 2, 2026. Each has captions; the player turns them on. Videos on YouTube can be changed or removed — if one no longer plays, tell your instructor. If a player does not appear, use its Watch on YouTube link.