Skip to content
ExamHope Logo

examhope

Primary Menu
  • Digital Logic
    • Arithmetic Operations
    • Asynchronous/Ripple Counters
    • Basic Gates
    • Boolean Algebraic Theorems
    • Codes
  • Data Structures
    • Binary Heaps
    • Binary Search
    • Binary Search Trees
    • Binary Tree
    • Binary Tree Sort
    • Bipartite Graphs
    • Complete Graph
  • Theory of Computation
    • Finite Automata
    • Finite Automaton First Example
  • Current Affairs
    • Sports News
    • Tech News
    • Bollywood News
    • Daily News
  • Database
  • Computer Network
  • Computer Organization and Architecture
  • C Language
  • Operating Systems
  • Software Engineering
  • Theory of Computation
  • About us
  • Contact Us
  • Privacy Policy
  • DMCA Policy
  • Terms and Conditions
  • Home
  • IT
  • Data Structures
  • Queue
  • Queue – Data Structures
  • Queue

Queue – Data Structures

examhopeinfo@gmail.com November 11, 2025 4 minutes read
Queue

Queue

What is a Queue?

Imagine you’re standing in line at a movie ticket counter.
The person who arrives first gets the ticket first, right?
And if you come late, you’ll have to wait until it’s your turn.

That’s exactly how a Queue works in programming!

A Queue is a linear data structure that follows the rule:
👉 FIFO – First In, First Out.

It means:

  • The first element added to the queue is the first one removed.
  • The last one added will have to wait for its turn.

So, if we think of it like a line of people:

  • New people join at the end (rear).
  • Service happens at the front.

🎯 Basic Concept

A queue has two ends:

  1. Front – where elements are removed.
  2. Rear – where elements are added.

Whenever you insert something, it goes to the rear.
Whenever you remove something, it comes out from the front.


🧱 Diagram of a Queue

Let’s picture it simply:

Front → [10] [20] [30] [40] ← Rear
  • If we enqueue (add) an element, it goes after 40.
  • If we dequeue (remove) an element, 10 leaves first.

That’s FIFO in action!


⚙️ Main Operations on a Queue

Let’s understand the basic actions we can perform on a queue.


🥇 1. Enqueue (Insertion)

This means adding a new element at the rear of the queue.

Example:

If your queue is [10, 20, 30]
and you enqueue 40, the new queue becomes:
[10, 20, 30, 40]

Here,

  • 10 is still at the front,
  • 40 is added at the rear.

Note:

If the queue is full and you still try to insert more, that’s called a Queue Overflow.


🥈 2. Dequeue (Deletion)

This means removing an element from the front of the queue.

Example:

If your queue is [10, 20, 30, 40]
and you dequeue one element,
the new queue becomes: [20, 30, 40]

10 — the first element — was removed.

Note:

If the queue is empty and you try to remove something, that’s called Queue Underflow.


🥉 3. Peek (Front Element)

Sometimes, you don’t want to remove anything —
you just want to see which element is at the front.

That’s what Peek does.

It simply shows the element at the front without changing the queue.

Example:
If the queue is [10, 20, 30], then Peek() = 10


🏅 4. Display

This operation simply prints or displays all the elements of the queue — from front to rear.

Example:
If the queue is [10, 20, 30, 40],
the display will look like this:

Front → 10  20  30  40 ← Rear

📘 Real-Life Examples of Queues

To make it easy, let’s look at where we see queues around us every day:

  1. 🚌 Bus Stop Line: People enter at the end and leave from the front.
  2. 🖨️ Printer Queue: Print jobs are handled one by one in the order they were added.
  3. ⏳ Customer Support: Your call is answered in the same order you joined the waiting list.
  4. 🚦 Traffic Line: Cars move in and out of a lane in the same sequence.

So, queues are not just a programming concept — they reflect real life!


🧮 Types of Queues

There are a few variations of the basic queue, depending on how you use it.

1. Simple Queue

  • Normal FIFO structure.
  • Elements added at rear, removed from front.

2. Circular Queue

  • The last position connects back to the first, forming a circle.
  • Useful to efficiently use memory.

3. Priority Queue

  • Each element has a priority.
  • The element with higher priority is served first (not just the one added first).

4. Double-Ended Queue (Deque)

  • Elements can be added or removed from both ends (front and rear).

💻 Simple Queue Diagram (Step by Step)

Step 1: Empty Queue
Front = -1, Rear = -1

Step 2: Enqueue(10)
[10]
Front → 0, Rear → 0

Step 3: Enqueue(20)
[10, 20]
Front → 0, Rear → 1

Step 4: Enqueue(30)
[10, 20, 30]
Front → 0, Rear → 2

Step 5: Dequeue()
[20, 30]
Front → 1, Rear → 2

Each enqueue moves the rear forward,
and each dequeue moves the front forward.


⚠️ Common Queue Errors

Error TypeWhen It Happens
OverflowWhen the queue is full and you try to add more elements.
UnderflowWhen the queue is empty and you try to remove an element.

Think of a ticket counter again:

  • If the line is already packed to the door — you can’t join (overflow).
  • If there’s no one left in line — you can’t remove anyone (underflow).

💻 Simple Pseudocode Example

#define MAX 5
int queue[MAX];
int front = -1, rear = -1;

void enqueue(int value) {
    if (rear == MAX - 1)
        printf("Queue Overflow");
    else {
        if (front == -1)
            front = 0;
        queue[++rear] = value;
    }
}

int dequeue() {
    if (front == -1 || front > rear)
        printf("Queue Underflow");
    else
        return queue[front++];
}

int peek() {
    if (front != -1)
        return queue[front];
}

About the Author

examhopeinfo@gmail.com

Administrator

Visit Website View All Posts

Post navigation

Previous: Operations on Stack — Data Structures
Next: Priority Queue — Data Structures

Related News

Queue MCQs For Data Structures
  • IT
  • Data Structures
  • Queue

Queue MCQs For Data Structures

examhopeinfo@gmail.com October 25, 2025 0

Recent Posts

  • Vivo X200: जाने कितनी कम कीमत पर मिल रहा ये 9400 मिडिया टेक प्रोसेसर वाला स्मार्टफोन
  • Samsung Galaxy S25 Plus पर मिल रही भारी छूट ,जाने सेल प्राइस
  • AI के इस ज़माने में कैसे बिजली बचा रहे हैं यह स्मार्ट प्लग?
  • क्या है यह GhostPairing Scam और बिना पासवर्ड और सिम के क्यों हो रहा है व्हाट्सप्प अकाउंट हैक
  • Leica कैमरे के साथ जल्द लॉन्च हो सकता है Xiaomi Ultra 17

At ExamHope, we understand that preparing for exams can be challenging, overwhelming, and sometimes stressful. That’s why we are dedicated to providing high-quality educational resources, tips, and guidance to help students and aspirants achieve their goals with confidence. Whether you are preparing for competitive exams, school tests, or professional certifications, ExamHope is here to make your learning journey smarter, easier, and more effective.

Quick links

  • About us
  • Contact Us
  • Privacy Policy
  • Terms and Conditions
  • Disclaimer
  • DMCA Policy

Category

  • Computer Network
  • Computer Organization and Architecture
  • Data Structures
  • C Language
  • Theory of Computation
  • Database

You may have missed

Vivo X200 Price Drop
  • IT
  • Current Affairs
  • Tech News

Vivo X200: जाने कितनी कम कीमत पर मिल रहा ये 9400 मिडिया टेक प्रोसेसर वाला स्मार्टफोन

examhopeinfo@gmail.com December 23, 2025 0
Samsung Galaxy S25 Plus
  • IT
  • Current Affairs
  • Tech News

Samsung Galaxy S25 Plus पर मिल रही भारी छूट ,जाने सेल प्राइस

examhopeinfo@gmail.com December 22, 2025 0
Electricity bill saving Smart Plug
  • IT
  • Current Affairs
  • Tech News

AI के इस ज़माने में कैसे बिजली बचा रहे हैं यह स्मार्ट प्लग?

examhopeinfo@gmail.com December 21, 2025 0
Ghost Pairing Scam on Whatsapp
  • IT
  • Current Affairs
  • Tech News

क्या है यह GhostPairing Scam और बिना पासवर्ड और सिम के क्यों हो रहा है व्हाट्सप्प अकाउंट हैक

examhopeinfo@gmail.com December 21, 2025 0
Copyright © All rights reserved for ExamHope. | MoreNews by AF themes.
Go to mobile version