Curriculum
Course: Grade XII Computer Science
Login
Text lesson

Ch-4 Queue

School Revise · Class 11 Computer Science · Chapter 4

Queue

Code 083, Class 12. A queue serves items in the order they arrive, first in first out, like a line at a shop. Here we build a queue with a Python list.

FIFO

first in, first out

list

used as a queue

What this chapter is about

A queue stores items so the first one added is the first one removed. This is FIFO, first in first out, like people waiting in a line.

1. Enqueue and dequeue

A list works as a queue. append() adds at the rear (enqueue) and pop(0) removes from the front (dequeue).

queue = [] queue.append(10) queue.append(20) print(queue.pop(0)) Output: 10

2. Front, rear and isEmpty

The front is queue[0] and the rear is queue[-1]. The queue is empty when its length is zero.

3. Where queues are used

Queues are used for printer jobs, for tasks waiting to run, and for messages, because the fair order is first come first served.

Practise with the interactive

Explore the idea by tapping. The interactive opens right here in the lesson.

Try it in the code lab

Write and run real Python right here in the lesson, then work through the practice problems with answers.

Starting Python...

Coding practice problems, with answers

Type each one into the code lab above, then open the card to see the worked solution and its output.

Problem 1. Enqueue items.

SOLUTION

queue = [] queue.append(10) queue.append(20) print(queue)

OUTPUT

[10, 20]
Problem 2. Dequeue the front item.

SOLUTION

q = [10, 20, 30] print(q.pop(0)) print(q)

OUTPUT

10 [20, 30]
Problem 3. See the front item.

SOLUTION

q = [10, 20, 30] print(q[0])

OUTPUT

10
Problem 4. Check if a queue is empty.

SOLUTION

q = [] print(len(q) == 0)

OUTPUT

True
Problem 5. Enqueue three items.

SOLUTION

q = [] for x in [1, 2, 3]: q.append(x) print(q)

OUTPUT

[1, 2, 3]
Problem 6. Dequeue all to see FIFO order.

SOLUTION

q = [1, 2, 3] while q: print(q.pop(0))

OUTPUT

1 2 3
Problem 7. Find the size of a queue.

SOLUTION

q = [5, 6, 7] print(len(q))

OUTPUT

3
Problem 8. See the rear item.

SOLUTION

q = [10, 20, 30] print(q[-1])

OUTPUT

30
Problem 9. Write an enqueue function.

SOLUTION

def enqueue(q, item): q.append(item) qu = [] enqueue(qu, 5) print(qu)

OUTPUT

[5]
Problem 10. Write a dequeue function with an empty check.

SOLUTION

def dequeue(q): if len(q) == 0: return “empty” return q.pop(0) print(dequeue([1, 2])) print(dequeue([]))

OUTPUT

1 empty

Practice set A, multiple choice

1. A queue works on which principle?

FIFO, first in first out.

2. Which method enqueues an item?

append().

3. Which removes the front item?

pop(0).

4. The front of a queue is at which index?

queue[0].

Quick summary

A queue is FIFO: the first item added is the first removed. A Python list is used as a queue: append() enqueues at the rear and pop(0) dequeues from the front. queue[0] is the front and queue[-1] is the rear. Queues suit printer jobs and any first come first served task.

Open the Virtual Lab

These free Class 12 Computer Science notes explain the queue data structure, FIFO, enqueue and dequeue using a Python list, and where queues are used with worked examples and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.

© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 12 Computer Science syllabus. Unauthorised copying is not permitted.

Layer 1
Login Categories