Thursday 28th March 2024
REGISTRATION
Online Fashion Store

CBSE Computer Science - Revision Tour(Solved)

CBSE Guess > eBooks > Class XII > CBSE Computer Science Link Lists Stacks And Queues Solved Revision Tour By Mr. Ravi Kiran

COMPUTER SCIENCE LINKED LISTS , STACKS AND QUEUES

Previous Index Next

OUTSIDE DELHI 2008:

3.c) Write a function in C++ to Delete an element into a dynamically allocated Queue where each node contains a real number as data. Assume the following definition of MYNODE for the same:

struct MYNODE
{ float NUM;
MYNODE * Link; };
Solution:
struct MYNODE
{
float NUM;
MYNODE *Link;
};
class Queue
{
MYNODE *front,*rear;
public:
Queue( )
{ front=rear=NULL; }
void Insert( );
void Delete( );
void Display( );
};
void Queue::Delete( )
{
MYNODE *temp;
if(front= = NULL)
cout<<”Queue Underflow”;
else
{
cout<<”\nThe content of the element to delete: “<<front → NUM;temp=front;
front=front → Link;
delete temp;
}
}

3.e) Evaluate the following postfix notation of expression (Show status of stack after execution of each operations): 5, 20, 15, -, *,25, 2, *, + 2

Ans) Children, Try this answer as an assignment.

DELHI : 2007

3.c) 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 ;
} ;
Solution: struct Book
{ int BNo ;
char BName[20] ;
Book *Next ;
} ;
class Stack
{ Book *Top;
public:
Stack( )
{ Top = NULL; }
void Push( );
void Pop( );
void Display( );
};
void Stack::Pop( )
{ Book *Temp;
If( Top= = NULL)
cout<<”Stack Underflow…”;
else
{ cout<<”\nThe Book number of the element to delete: “<<Top → BNo;
cout<<”\nThe Book name of the element to delete: “<<Top → BName;
Temp=Top;
Top=Top → Next;
Delete Temp;
}
}
}

 

Previous Index Next

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )