CBSE Class 12 Computer Science Stacks Queues And Linked List Worksheet

Chapter-wise Worksheets for Class 12 Computer Science: Stacks Queues And Linked List

Access comprehensive chapter-wise worksheets for Stacks Queues And Linked List using the CBSE Class 12 Computer Science Stacks Queues And Linked List Worksheet. Designed to align with the 2026-27 academic syllabus for Class 12 Computer Science, these printable practice sets help students reinforce key concepts and improve their overall exam readiness.

Practice Class 12 Computer Science Worksheets: Stacks Queues And Linked List

Access the complete worksheet PDF for Class 12 Computer Science below. Regular practice with these targeted academic tasks builds familiarity with standard question patterns and helps secure higher marks in final school examinations.

Stacks, Queues and Linked List

Stack

In computer science, a stack represents a linear data structure following the Last-In, First-Out (LIFO) mechanism. Under this principle, the element placed into the structure most recently is the first one removed. Both insertion and removal activities occur exclusively at a single terminal called the "top". A standard practical implementation of stacks is handling function and subprogram calls in computer systems.

Operations on the Stack

A stack supports two primary primitive operations:

  • Push: Adds a new data element onto the top of the stack.
  • Pop: Removes the most recently added element from the top of the stack.

Queue

A queue is a linear collection governed by the First-In, First-Out (FIFO) principle. This dictates that whichever item arrives earliest will be processed and removed first. Queue operations are managed from two distinct positions named "front" and "rear". Every new entry is appended at the rear end, whereas deletion is performed from the front end.

Linked List

A linked list is a dynamic collection composed of distinct nodes that sequentially link together. In its basic representation, every node contains two components: an informational data field and a pointer (or reference) that holds the address of the subsequent node. More intricate variants include additional pointers (such as doubly linked lists). This design enables rapid insertion or deletion of members at any position.

12 99 37

The diagram demonstrates a singly linked list where each node holds an integer value along with a link directed to the next node. The terminal node links to a null indicator (marked with an X) to signify the end of the sequence. Linked lists are commonly used to construct other data structures, such as dynamic stacks and queues.

The main advantage of a linked list over a traditional array is that items can be inserted or deleted without shifting or reallocating adjacent memory blocks, as elements do not require contiguous storage. A linked list is dynamic, meaning memory allocation occurs at run time as needed.

Operation on a Linked List

There are three fundamental operations performed on a linked list:

  • Insertion
  • Deletion
  • Traversal

Inserting a Node or Element into a Linked List

New nodes can be inserted into a linked list in three ways:

1. Insertion at the beginning of the linked list
2. Insertion after or before any specified node of the linked list
3. Insertion at the end of the linked list

Deleting a Node from the Linked List

Similarly, a node can be removed from a linked list in three ways:

1. Deleting a node from the beginning of the linked list
2. Deleting a node before or after a specified node from the linked list
3. Deleting a node from the end of the linked list

Implementation of Stacks Using a Linked List

When a stack is constructed with dynamic node pointers instead of a static array, it is called a linked stack or dynamic stack.

#include<iostream.h>
#include<conio.h>

struct node 
{ 
    int data; 
    node *next; 
}; 

class stack 
{ 
    node *top; 
public: 
    stack() 
    { 
        top = NULL; 
    } 
    void stackpush(); 
    void stackpop(); 
    void displaystack(); 
}; 

void stack::stackpush()
{ 
    node *ptr; 
    ptr = new node; 
    cout << "Enter the element to be pushed" << endl;
    cin >> ptr->data; 
    if(top == NULL) 
        ptr->next = NULL; 
    else 
        ptr->next = top; 
    top = ptr; 
} 

void stack::stackpop() 
{ 
    node *ptr; 
    ptr = top; 
    cout << "The popped element is " << ptr->data; 
    top = top->next; 
    delete ptr; 
} 

void stack::displaystack() 
{ 
    node *ptr; 
    ptr = top; 
    cout << "The stack is " << endl; 
    while(ptr != NULL) 
    { 
        cout << ptr->data << endl; 
        ptr = ptr->next; 
    } 
} 

void main() 
{ 
    clrscr(); 
    char ans; 
    stack s1; 
    do 
    { 
        s1.stackpush(); 
        cout << "wish to continue " << endl; 
        cin >> ans; 
    } while(ans == 'y'); 

    s1.displaystack(); 
    cout << "Press any key to pop an element" << endl; 
    getch(); 
    s1.stackpop(); 
    s1.displaystack(); 
    getch(); 
}

Implementation of Queues Using a Linked List

A queue created using linked nodes rather than fixed-size storage is termed a linked queue or dynamic queue.

#include<iostream.h> 
#include<conio.h> 

struct node 
{ 
    int data; 
    node *next; 
}; 

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

void queue::insqueue() 
{ 
    node *ptr; 
    ptr = new node; 
    cout << "Enter the element to be insert" << endl; 
    cin >> ptr->data; 
    ptr->next = NULL; 
    if(rear == NULL) 
        front = rear = ptr; 
    else 
    { 
        rear->next = ptr; 
        rear = ptr; 
    } 
} 

void queue::delqueue() 
{ 
    node *ptr; 
    ptr = front; 
    cout << "The deleted element is " << ptr->data; 
    if(front == rear) 
        front = rear = NULL; 
    else 
        front = front->next; 
    delete ptr; 
} 

void queue::dispqueue() 
{ 
    node *ptr; 
    ptr = front; 
    cout << "The queue is " << endl; 
    while(ptr != NULL) 
    { 
        cout << ptr->data << endl; 
        ptr = ptr->next; 
    } 
} 

void main() 
{ 
    clrscr(); 
    char ans; 
    queue q1; 
    do 
    { 
        q1.insqueue(); 
        cout << "wish to continue " << endl; 
        cin >> ans; 
    } while(ans == 'y'); 

    q1.dispqueue(); 
    cout << "Press any key to delete an element ...." << endl; 
    getch(); 
    q1.delqueue(); 
    q1.dispqueue(); 
    getch(); 
}

Some Questions Based on Board Examination on Linked Stack & Linked Queue

 

Question 1. Write a function in C++ to delete a node containing customer’s information, from a dynamically allocated Queue of Customers implemented with the help of the following structure:
struct Customer
{int CNo;
char CName[20];
Customer *Link;
};
Answer:
 

struct Customer 
{ 
    int CNo; 
    char CName[20]; 
    Customer *Link; 
} *Front, *Rear, *ptr; 

void DELETE() 
{ 
    if(Front == NULL) 
    {
        cout << "\n Queue Underflow\n"; 
    }
    else 
    { 
        ptr = Front; 
        Front = Front->Link; 
        delete ptr; 
    } 
}

The function begins by testing if Front points to NULL, signaling that no customer nodes reside in the queue, which triggers an underflow notification. If nodes exist, the pointer ptr captures the address of the current Front node, Front advances to the subsequent customer via Front->Link, and the freed node's dynamically allocated memory gets discarded using the delete command.
In simple words: To delete a customer from the queue, first confirm whether the list is empty. If it holds data, store the leading node's location, slide the front pointer forward to the next person, and remove the detached record from memory.
Exam Tip: In linked queue deletion questions, always write the underflow validation condition (Front == NULL) and deallocate memory using delete ptr to avoid deduction of marks.

 

Question 2. Write a function in C++ to delete a node containing Book’s information, from a dynamically allocated Stack of Books implemented with the help of the following structure.
struct Book
{int BNo;
char BName[20];
Book *Next;
};
Answer:
 

struct Book 
{ 
    int BNo; 
    char BName[20]; 
    Book *Next; 
} *top, *ptr; 

void POP() 
{ 
    if(top == NULL) 
    {
        cout << "\n Stack Underflow\n"; 
    }
    else 
    { 
        ptr = top; 
        top = top->Next; 
        delete ptr; 
    } 
}

The routine first checks whether the pointer top equates to NULL, writing a "Stack Underflow" message if no books remain to pop. When valid records are found, ptr marks the uppermost book, top shifts downward to top->Next, and delete ptr reclaims the memory occupied by the popped item.
In simple words: First confirm the stack is not empty before popping. If an item exists, move the top pointer to the book below it and free the old top node.
Exam Tip: Stacks operate from a single end, so verify that both checking underflow and advancing the pointer use the top pointer.

 

Question 3. Evaluate the postfix notaion of expression.
4, 10 , 5 , + , * , 15 , 3 ,/ , -
Answer:
To evaluate the postfix expression, each token is scanned sequentially from left to right. Operands get pushed directly onto the stack. When an operator is encountered, the top two values are popped, the corresponding mathematical operation is computed, and the outcome is pushed back onto the stack.

S. No.Scanned SymbolOperation PerformedStack Contents
0InitialInitialize empty stack[ ]
14Push(4)[4]
210Push(10)[4, 10]
35Push(5)[4, 10, 5]
4+Pop 5, Pop 10; Evaluate \( 10 + 5 = 15 \); Push(15)[4, 15]
5*Pop 15, Pop 4; Evaluate \( 4 \times 15 = 60 \); Push(60)[60]
615Push(15)[60, 15]
73Push(3)[60, 15, 3]
8/Pop 3, Pop 15; Evaluate \( 15 / 3 = 5 \); Push(5)[60, 5]
9-Pop 5, Pop 60; Evaluate \( 60 - 5 = 55 \); Push(55)[55]
10End of ExpressionPop result55

Final Answer: 55
In simple words: Read symbols one by one; put numbers into the stack and, whenever an operator appears, pull out the top two digits, calculate the result, and place it back. The single value left on the stack is 55.
Exam Tip: Be careful with operand order during division and subtraction: the first popped element is operand 2, and the second popped element is operand 1 (i.e., evaluate \( \text{operand 1} - \text{operand 2} \)).

 

Question 4. Convert the following infix expression to its equivalent postfix expression, showing the stack contents for each step of conversion.
X / Y + U* (V-W)
Answer:
Parenthesized form of the given infix expression: 
\( ((X / Y) + (U * (V - W))) \)

Scanned ElementOperator StackPostfix Expression
(( 
((( 
X((X
/((/X
Y((/XY
)(XY/
+(+XY/
((+(XY/
U(+(XY/U
*(+(*XY/U
((+(*(XY/U
V(+(*(XY/UV
-(+(*(-XY/UV
W(+(*(-XY/UVW
)(+(*XY/UVW-
)(+XY/UVW-*
)EmptyXY/UVW-*+

Equivalent Postfix Expression: XY/UVW-*+
In simple words: Operands are routed straight to the postfix line, while operators rest in the stack until corresponding brackets terminate or higher-priority operations complete. The converted postfix form is XY/UVW-*+.
Exam Tip: Showing every single step in tabular form is essential for full marks; make sure to clearly reflect how right parentheses cause operators to pop until the opening parenthesis is matched.

 

Please click the link below to download full pdf file for CBSE Class 12 Computer Science Stacks Queues and Linked List.

Stacks Queues And Linked List Printable Worksheets and Exercises for Class 12 Computer Science

Practice Exercises for Class 12 Computer Science Stacks Queues And Linked List

Explore reliable practice questions for Stacks Queues And Linked List tailored for Class 12 Computer Science learners. Use these structured worksheets to evaluate exam preparedness and strengthen problem-solving skills throughout the 2026 academic session.

Step-by-Step Solutions and Practice Guidelines

Built using official NCERT guidelines for Class 12 Computer Science, these practice sheets provide reliable academic support. Cross-reference your completed work with our detailed solutions to learn standard answer-writing formats for CBSE exams.

Enhance Speed with Online Practice

Consistent engagement with these exercises builds familiarity with recurring exam themes. If specific areas within Stacks Queues And Linked List cause trouble, utilize our dedicated NCERT solutions for Class 12 Computer Science to clear up doubts immediately.

FAQs

Where can I download the 2026-27 CBSE printable worksheets for Class 12 Computer Science Stacks Queues And Linked List?

You can download the latest chapter-wise printable worksheets for Class 12 Computer Science Stacks Queues And Linked List for free from StudiesToday.com. These have been made as per the latest CBSE curriculum for this academic year.

Are these Stacks Queues And Linked List Computer Science worksheets based on the new competency-based education (CBE) model?

Yes, Class 12 Computer Science worksheets for Stacks Queues And Linked List focus on activity-based learning and also competency-style questions. This helps students to apply theoretical knowledge to practical scenarios.

Do the Class 12 Computer Science Stacks Queues And Linked List worksheets have answers?

Yes, we have provided solved worksheets for Class 12 Computer Science Stacks Queues And Linked List to help students verify their answers instantly.

Can I print these Stacks Queues And Linked List Computer Science test sheets?

Yes, our Class 12 Computer Science test sheets are mobile-friendly PDFs and can be printed by teachers for classroom.

What is the benefit of solving chapter-wise worksheets for Computer Science Class 12 Stacks Queues And Linked List?

For Stacks Queues And Linked List, regular practice with our worksheets will improve question-handling speed and help students understand all technical terms and diagrams.