Wednesday

Important Questions for Class 12 Computer Science (C++) – Linked List, Stack and Queue

 

Topic – 1
Linked List and Stack
Previous years Examination Questions
2 Marks Questions

Question 1:
Convert the following infix expression to its equivalent postfix expression, showing the stack contents for each step of conversion:
P/(Q-R)*S + T All India 2016
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(222-1)

Question 2:
Convert the following infix expression to its equivalent postfix expression, showing the stack contents for each step of conversion.
A/(B + Q*D-E Delhi 2016
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(222-2)
important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(222-3)

Question 3:
Convert the following infix expression to its equivalent postfix expression, showing the stack contents for each step of conversion.
P/(Q+(R-T)*U All India (C) 2016
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(222-4)
important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(223-1)

Question 4:
Convert the following infix expression to its equivalent postfix expression, showing the stack contents for each step of conversion:
(U* V+ R/ (S-T)) All India 2015
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(223-2)

Question 5:
Convert the following infix expression to its equivalent postfix expression, showing the stack contents for each step of conversion.
(X/Y+U*(V-W)) Delhi 2015
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(223-3)

Question 6:
Evaluate the following postfix expression. Show the. status of stack after execution of each operation separately:
F, T, NOT, AND, F, OR, T, AND   Delhi 2014
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(223-4)

Question 7:
Evaluate the following postfix expression. Show the status of stack after execution of each operation separately:
T, F, NOT, AND, T, OR, F, AND    All India 2014
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(223-5)

Question 8:
Evaluate the following postfix expression: (show status of stack after each operation)
100,40,8,/,20,10,-,+,*     All India (C) 2014
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(224-1)

Question 9:
Evaluate the following postfix expression. Show the status of stack after execution of each operation:
5, 2, *, 50, 5, /, 5, -, +      All India 2013
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(224-2)

Question 10:
Evaluate the following postfix expression. Show the status of stack after execution of each operation:
60, 6, /, 5, 2, *, 5, -, +     Delhi 2013
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(224-3)

Question 11:
Evaluate the following postfix expression using a stack and show the contents of stack after execution of each operation:
5, 3, 2, *, 4, 2, /, -, *      Delhi 2013C
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(224-4)
important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(224-5)

Question 12:
Evaluate the following postfix notation. Show status of stack after every step of evaluation (i.e. after each operator):
False, NOT, True, AND, True, False, OR, AND      Delhi 2012
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(224-6)

Question 13:
Evaluate the following postfix notation. Show status of stack after every step of evaluation (i.e. after each operator):
True, False, NOT, AND, False, True, OR, AND    All India 2012
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(224-7)

Question 14:
Evaluate the following postfix notation of expression:
50, 60, +, 20, 10, – ,*      Delhi 2011
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(225-1)

Question 15:
Evaluate the following postfix notation of expression:
True, False, NOT, AND, True, True, AND, OR  All india 2011
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(225-2)

Question 16:
Evaluate the following postfix notation of expression:
False, True, NOT, OR, True, False, AND, OR   Delhi 2010
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(225-3)
important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(225-4)

Question 17:
Evaluate the following postfix notation of expression. Show the status of stack after each operation:
True, False, NOT, OR, False, True, OR, AND  All  India 2010
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(225-5)

Question 18:
Convert the following infix expression to its equivalent postfix expression.
Showing stack contents for the conversion:
(X – Y/(Z+U)*V)    Delhi 2009
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(226-1)

Question 19:
Convert the following infix expression to its equivalent postfix expression.
Showing stack contents for the conversion:
(A + B* (C-D) IE) All India 2009
Аnswer:

important-questions-for-class-12-computer-science-c-linked-list-stack-and-queue-(226-2)

4 Marks Questions

Question 20:
Write the definition of a member function PUSH( ) in C++, to add a new book in a dynamic stack of BOOKS considering the following code is already included in the program: All India 2015

struct BOOKS 
{
char ISBN[20], TITLE[80];
BOOKS *Link;
};
class STACK 
{
BOOKS *Top; 
public:
STACK() {Top=NULL;} 
void PUSH(); 
void POP();
∼STACK();
 };

Аnswer:

void STACK::PUSH()
{
BOOKS *b = new BOOKS; 
cout<<"Enter ISBN number"; 
cin>>b->ISBN; 
cout<<"Enter TITLE"; 
gets(b—>TITLE); 
if(TOP == NULL)
{
TOP = b;
}
else
{
b->Link = TOP; 
TOP = b;
}
}

Question 21:
Write the definition of a member function Pop( ) in C++, to delete a book from a dynamic stack of TEXTBOOKS considering the following code is already included in the program. Delhi 2015

struct TEXTBOOKS
{
char ISBN[20]; 
char TITLE[80]; 
TEXTBOOKS *Link;
};
class STACK 
{
TEXTBOOKS *Top; 
public:
STACK(){Top=NULL;} 
void Push(); 
void Pop();
∼STACKC);
};

Аnswer:

void STACK::Pop()
{
if(Top! = NULL)
{
TEXTBOOKS *Temp = Top;
Top = Top->Link; 
delete Temp; 
}
else
cout<<"Stack empty";
}

Question 22:
Write a function POPBOOK( ) in C++ to perform delete operation from a dynamic stack, which contains Bno and Title. Consider the following definition of NODE, while writing your C++ code.  Delhi 2014

struct NODE
{
int Bno;
char Title[20];
NODE *Link;
};

Аnswer:

void P0PB00K(N0DE *top)
{
cout<<:Deleting the top element from stack\n"; 
cout<<"Book No:"<<top->Bno<<endl; 
cout<<"BookTitle:"<<top->Title<<endl;
NODE *temp = top;
top = top->Link; 
delete(temp);
}

Question 23:
Write a function PUSHBOOK( ) in C++ to perform insert operation on a dynamic stack, which contains Book_no and Book_Title. Consider the following definition of NODE, while writing your C++ code. All India 2014

struct NODE 
{
char Book_No; 
char Book_Title[20]:
NODE *Next:
};

Аnswer:

void PUSHBOOK(NODE *top)
{
NODE *NEW = new NODE; 
cout<<"Enter the Book Number:"; 
cin>>NEW->Book_No; 
cout<<"Enter the Book Title:"; 
gets(NEW->Book_Titie);
NEW->Next = NULL; 
if(top == NULL)
top = NEW; 
else 
{
NEW->Next = top; 
top = NEW;
}
}

Question 24:
Write a complete program in C++ to implement a dynamically allocated stack containing names of Countries. Delhi 2010
Аnswer:

The program is:
#include<iostream.h>
#include<stdio.h>
struct Node
{ 
char Country[30];
Node *Link;
};
class Stack 
{
Node *Top; 
public:
Stack(){Top = NULL;} 
void Push(); 
void Pop();
void Display();
∼Stack();
};
void Stack :: Push()
{
Node *Temp = new Node; 
gets(Temp->Country); 
Temp->Link = Top;
Top = Temp;
}
void Stack :: Pop()
{
if(Top!=NULL) 
{
Node *Temp = Top;
Top = Top->Link; 
delete Temp;
}
else
cout<<"Stack empty";
}
void Stack :: Display()
{
Node *Temp = Top; 
while(Temp!= NULL)
cout<<Temp->Country<<endl; 
Temp = Temp->Link;
Stack :: ∼Stack()
{
while(Top!=NULL)
{
Node *Temp = Top;
Top = Top->Link; 
delete Temp;
}
}
void main()
{
Stack ST; 
char ch; 
do 
{
cout<<"Choose any one P/O/D/Q"; /* displaying choices P - Push,0 - Pop, D-Display, Q-Exit */ 
cin>>ch; 
switch(ch)
{
case 'P':ST.Push(); 
break;
case '0':ST.Pop(); 
break;
case 'D':ST.Display();
}
}
while(ch!='Q');
}

0 comments:

Post a Comment

Thanks for leaving a comment. As soon as it's approved, it will appear.