CBSE Class 12 Computer Science Chapter 10: Queue NCERT Solutions

NCERT Solutions PDF Class 12 PDF

CBSE Class 12 Computer Science Chapter 10 introduces the Queue data structure, offering detailed NCERT Solutions. This chapter delves into the core concepts of queues, emphasizing their implementation through linked lists. It provides clear, step-by-step explanations and practical C++ code examples for performing key operations, particularly focusing on the deletion of elements from a linked queue. The solutions are crafted to ensure students develop a thorough understanding of the logic behind queue management. This resource is an excellent tool for exam preparation and revision, helping students master the intricacies of this important data structure.

Quick info

BoardCBSE
ClassClass 12
SubjectComputer Science (C++)
Session2026
LanguageEnglish
TypeNCERT Solutions
ChapterChapter 10

Chapter summary

Chapter 10 focuses on the Queue data structure, specifically its implementation and operations using linked lists in C++. The NCERT Solutions provided here offer detailed explanations and code for the delete operation (delque, QUEUEDEL, QDELETE) on a linked queue. It covers scenarios for both non-empty and empty queues, ensuring students understand how to handle different conditions when removing elements.

Learning outcomes

  • Understand the concept of a queue and its operations.
  • Implement a linked queue in C++.
  • Write C++ functions to delete elements from a linked queue.
  • Handle the case of an empty queue during deletion.
  • Analyze the structure of nodes in a linked queue.

Topics covered

Paper topics

  • Queue Data Structure
  • Linked List Implementation
  • Queue Deletion Operation
  • C++ Programming
  • Node Structure
  • Pointer Manipulation
  • Handling Empty Queues
  • Memory Management (delete)

Important topics

  • Linked Queue Deletion Logic
  • Pointer Updates (front, rear)
  • Empty Queue Condition
  • Node Structure for Queues

PDF preview

Read page by page below. PDF is streamed from the official NCERT website — no download button on this page.

Loading document …
Page of
Loading page …

Questions and Solutions

Question 1

Define the member function `delque()` to perform the delete operation on a linked queue where each node has the following structure:

struct node { char name[20]; int marks; node *link; };

class queue { node *front, *rear; public: queue() {front=rear=NULL;} void delque(); };

[CBSE Comptt., 2014]

Solution:

The `delque()` function removes the element from the front of the linked queue. It first checks if the queue is empty by verifying if the `front` pointer is `NULL`. If the queue is not empty, it stores the current `front` node in a temporary pointer `Temp`, displays the data of the node being deleted, and then updates the `front` pointer to the next node in the queue (`front = front->link`). If, after updating `front`, it becomes `NULL`, it means the queue is now empty, so the `rear` pointer is also set to `NULL`. Finally, the memory occupied by the deleted node is freed using `delete Temp;`.

void queue::delque() {

if (front != NULL) {

node *Temp = front;

cout << "Deleted Element: " << Temp->name << " " << Temp->marks << endl;

front = front->link;

delete Temp;

if(front == NULL)

rear = NULL;

} else {

cout << "Queue is empty" << endl; } }

(4 marks for correct program)

Question 2

Give the necessary declaration of a linked implemented Queue containing player information (as defined in the following definition of Node). Also, write a user-defined function in C++ to delete one Player's information from the Queue.

struct node { int PlayerNo; char PlayerName[20]; Node*Link; };

[CBSE Comptt., 2013]

Solution:

First, we define the structure for the queue node, which includes player number, player name, and a pointer to the next node. The function `QUEUEDEL` is designed to delete a player's information from the front of the linked queue. It takes the current `front` pointer as an argument. It checks if the queue is empty (`front == NULL`). If it is, an "Queue EMPTY" message is displayed. Otherwise, it uses a temporary pointer `temp` to hold the current `front` node. The data from this node (player number and name) is conceptually processed or displayed (though the provided snippet shows assignment to `val` and `val2` which are not used in the function signature, implying they might be for output or a different function design). The `front` pointer is then moved to the next node (`front = front->Link`), and the memory of the original front node is deallocated using `delete temp`. The function returns the updated `front` pointer.

Node Declaration:

struct node {

int PlayerNo;

char PlayerName[20];

Node*Link; }; Function to delete from Queue:

Node* QUEUEDEL(Node * front) { // Assuming val and val2 were placeholders or for a different purpose

Node *temp;

if (front == NULL) {

cout << "Queue EMPTY" << endl;

} else {

temp = front;

// Displaying or processing the deleted data (example):

cout << "Deleting Player No: " << temp->PlayerNo << ", Name: " << temp->PlayerName << endl;

front = front->Link;

delete temp; } return (front); } [1] indicates marks allocation in the original source.

Question 3

Write a function `QDELETE()` in C++ to perform the delete operation on a Linked Queue, which contains Passenger no and Passenger name. Consider the following definition of Node in the code.

struct node { long int Pno; char Pname [20]; node *Link; };

[O.D, 2013]

Solution:

The `QDELETE()` function is designed to remove a passenger's record from the front of a linked queue. It assumes the queue is managed by `front` and `rear` pointers, typically part of a `Queue` class. The function first checks if the queue is empty by testing if `front` is `NULL`. If the queue is empty, it prints a message indicating this. If the queue is not empty, it uses a temporary pointer `Temp` to point to the `front` node. The data from this node (passenger number and name) can be accessed via `Temp` for display or further processing before deletion. The `front` pointer is then advanced to the next node in the queue (`front = front->Link`). If advancing `front` makes it `NULL`, it signifies that the queue has become empty, and thus the `rear` pointer must also be set to `NULL`. Finally, the memory allocated for the node being removed is released using `delete Temp;`.

// Assuming this function is a member of a class with front and rear pointers

void QDELETE() {

if (front != NULL) {

node *Temp = front;

cout << "Deleting Passenger No: " << Temp->Pno << ", Name: " << Temp->Pname << endl;

front = front->Link;

delete Temp;

if (front == NULL) {

rear = NULL; // Update rear if the queue becomes empty } } else {

cout << "Queue is empty. Cannot delete."; } }

Common mistakes

  • Incorrectly handling the case when the queue is empty.
  • Failing to update the 'front' and 'rear' pointers correctly after deletion.
  • Memory leaks due to improper deallocation of deleted nodes.
  • Confusing queue operations with stack operations.

Revision tips

  • Review the node structure and pointer manipulation for linked lists.
  • Trace the execution of the deletion function with an empty and a non-empty queue.
  • Pay close attention to updating 'front' and 'rear' pointers after deletion.
  • Practice writing the deletion function from scratch without referring to the solution.

Practice MCQs

Q1. What is the primary operation demonstrated in these NCERT Solutions for Chapter 10?

Q2. In a linked queue, what happens to the 'front' pointer after deleting the first element?

Q3. What is the crucial check performed before attempting to delete an element from a linked queue?

Q4. What is the purpose of the 'Temp' pointer in the deletion functions?

Q5. If a linked queue becomes empty after a deletion, what should happen to the 'rear' pointer?

Frequently asked questions

What is a queue in the context of Computer Science?

A queue is a linear data structure that follows the First-In, First-Out (FIFO) principle, meaning the first element added to the queue is the first one to be removed.

How is a linked queue different from an array-based queue?

A linked queue uses nodes connected by pointers, allowing dynamic resizing, whereas an array-based queue uses a fixed-size array, which can lead to overflow issues.

What does the `delque()` function do in a linked queue?

The `delque()` function is responsible for removing and returning the element at the front of the linked queue. It also handles updating the 'front' pointer and deallocating the memory of the removed node.

What is the significance of checking if `front != NULL` before deletion?

This check is crucial to ensure that the queue is not empty. Attempting to delete from an empty queue would lead to errors or undefined behavior.

What happens if the queue becomes empty after deleting an element?

If the deleted element was the last one in the queue, both the 'front' and 'rear' pointers should be set to `NULL` to correctly represent an empty queue.

Are the node structures provided in the questions consistent across all examples?

The node structures are similar, defining data fields (like name, marks, PlayerNo, Pname) and a pointer (`link`) to the next node. The specific field names and types may vary slightly based on the problem context.

Content reviewed by the NCERT Help team. Editorial Team and update policy

NCERT Solutions PDF PDF on NCERT Help. URL unchanged for search indexing.