CBSE Class 12 Computer Science Chapter 10: Queue NCERT Solutions

NCERT Solutions PDF Class 12 PDF

This resource provides detailed NCERT Solutions for Chapter 10: Queue in CBSE Class 12 Computer Science. It covers the fundamental concepts of queues, focusing on their implementation using linked lists. The solutions explain the process of deleting elements from a linked queue, ensuring that students understand how to manage the front and rear pointers and handle empty queue scenarios. These solutions are designed to clarify the logic behind queue operations, helping students grasp the practical application of data structures in C++. By working through these solved problems, students can reinforce their understanding of queue management, which is crucial for their exam preparation and overall comprehension of computer science principles.

Quick info

BoardCBSE
ClassClass 12
SubjectComputer Science
Session2026
LanguageEnglish
TypeNCERT Solutions
Chapter10. Queue

Chapter summary

This chapter focuses on the Queue data structure, specifically its implementation using linked lists in C++. The NCERT Solutions provide step-by-step guidance on performing the delete operation (dequeue) on a linked queue. It covers the necessary node and class declarations and demonstrates how to handle the deletion of elements while managing the front and rear pointers, including the case of an empty queue. These solutions are essential for understanding dynamic queue management.

Learning outcomes

  • Understand the concept of a queue data structure.
  • Learn how to implement a linked queue in C++.
  • Implement the delete operation (dequeue) for a linked queue.
  • Handle edge cases such as deleting from an empty queue.
  • Apply knowledge of pointers and dynamic memory allocation in queue operations.

Topics covered

Paper topics

  • Queue Data Structure
  • Linked List Implementation
  • Dequeue Operation
  • C++ Programming
  • Node Structure
  • Class Definition
  • Pointer Manipulation
  • Handling Empty Queues

Important topics

  • Linked Queue Implementation
  • Dequeue Operation Logic
  • Pointer Management in Linked Structures
  • Edge Case: Empty Queue Handling

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 ( ); };

Solution:

The `delque()` function removes an 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, prints the data of the element being deleted, updates the `front` pointer to the next node in the list, and then deallocates the memory occupied by the temporary node. If the queue becomes empty after deletion (i.e., `front` becomes NULL), the `rear` pointer is also set to NULL.

void queue :: delque ( ) { if ( front != NULL ) { node *Temp = front;

cout << Temp->name << " " << Temp->marks;

front = front->link;

delete Temp;

if(front == NULL)

rear = NULL; } else

cout << "Queue is empty"; }

Question 2

Give the necessary declaration of a linked implemented Queue containing players' 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; };

Solution:

This question asks for the declaration of a linked queue and a function to delete a player's information. The deletion function, `QUEUEDEL`, takes the current `front` pointer and the data of the player to be deleted (though the provided solution doesn't use the `val` and `val2` parameters for deletion logic, it assumes deletion from the front). It checks if the queue is empty. If not, it uses a temporary pointer to hold the current `front`, updates `front` to point to the next node, deletes the temporary node, and returns the new `front` pointer. The parameters `val` and `val2` seem extraneous for a standard front-deletion operation in a linked queue as typically implemented.

// Necessary declarations for the Node and Queue class

struct node {

int PlayerNo;

char PlayerName[20];

node* Link; }; // Assuming a Queue class with front and rear pointers

class Queue {

node *front, *rear;

public:

Queue() { front = rear = NULL; }

// Other functions like enqueue, display, etc.

node* QUEUEDEL(node* f_ptr); // Modified to take only front pointer for standard deletion }; // Function to delete a player's information from the front of the queue

node* Queue::QUEUEDEL(node* front_ptr) {

node* temp;

if (front_ptr == NULL) {

cout Link;

delete temp;

// If the queue becomes empty, update rear as well (assuming rear is a member variable)

if (front_ptr == NULL) {

rear = NULL; // This line would be inside the class method if 'rear' is a member } }

return front_ptr; // Return the updated front pointer } /*

Note: The original provided solution snippet `Node *QUEUEDEL(Node * front, int val, char val2[])`

and its implementation `temp®PlayerNo=val; strcpy (temp®PlayerName, val2);`

suggested modifying the node's data before deletion, which is unusual for a delete operation.

The rewritten solution above assumes a standard dequeue operation that removes the front element.

If the intention was to delete a specific player by value, the logic would be different and require searching the list. */

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; };

Solution:

The `QDELETE()` function is designed to remove a passenger's record from the front of a linked queue. It first checks if the queue is empty by examining the `front` pointer. If the queue is not empty, a temporary pointer `Temp` is used to point to the current `front` node. The function then proceeds to update the `front` pointer to the next node in the sequence (`front->Link`). After that, the memory occupied by the node pointed to by `Temp` is deallocated using `delete Temp`. A crucial step is to check if the queue becomes empty after this deletion; if `front` is now NULL, it means the last element was removed, and `rear` should also be set to NULL to reflect the empty state of the queue. If the queue was initially empty, an appropriate message is displayed.

// Assuming 'front' and 'rear' are member pointers of a Queue class

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

void Queue::QDELETE( ) { node *Temp;

if ( front != NULL ) // Check if the queue is not empty { Temp = front; // Store the current front node in Temp

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

front = front->Link; // Move front to the next node

delete Temp; // Deallocate the memory of the deleted node

// If the queue becomes empty after deletion, update rear pointer

if ( front == NULL ) { rear = NULL; } cout << "\nPassenger deleted successfully."; } else { cout << "Queue is empty. Cannot delete."; } }

Common mistakes

  • Incorrectly updating the front and rear pointers after deletion.
  • Failing to handle the case where the queue becomes empty after deletion.
  • Memory leaks due to improper deletion of nodes.
  • Confusing queue operations with stack operations.

Revision tips

  • Review the node structure and class definition for a linked queue.
  • Trace the `delque()` function with different scenarios (non-empty, empty queue).
  • Pay close attention to pointer manipulation (front, rear, link).
  • Practice writing the delete function from scratch to reinforce understanding.

Practice MCQs

Q1. What is the primary operation performed by the `delque()` function in a linked queue?

Q2. In a linked queue, if `front` is not NULL, what is the first step in the deletion process?

Q3. What happens to the `rear` pointer when the last element is deleted from a linked queue?

Q4. If `front` is NULL when `delque()` is called, what is the expected output?

Frequently asked questions

What is a queue in 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 implemented?

A linked queue is implemented using nodes, where each node contains data and a pointer to the next node. Pointers like `front` and `rear` manage the beginning and end of the queue.

What does the `delque()` function do?

The `delque()` function performs the dequeue operation, which involves removing the element from the front of the queue and updating the `front` pointer accordingly.

What happens if you try to delete from an empty queue?

If you attempt to delete from an empty queue (where `front` is NULL), an 'Queue is empty' message is typically displayed to indicate that no element can be removed.

Why is a temporary pointer used in the deletion process?

A temporary pointer is used to store the address of the node being deleted. This allows the `front` pointer to be updated to the next node before the original front node is deallocated from memory.

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

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