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

DELHI : 2003

3.c) Evaluate the following postfix expression using a stack and show the contents of stack after execution of each operation: 20, 45, +, 20, 10, -, 15, +, *.

Ans) Children, Try this answer as an.

3.e) Consider the following portion of a program, which implements passengers Queue for a train. Write the definition of function. Insert (whose prototype is shown below); to insert a new node in the queue with required information.

struct NODE
{ long Ticketno;
char
PName[20];//Passengers Name
NODE * Next;
};
class Queueoftrain
{ NODE * Rear, * Front;
public :
Queueoftrain( ) { Rear = NULL; Front = NULL:}
void Insert( );
void Delete( );
~Queueoftrain( );
} ;

Solution:

void Queueoftrain::Insert( )
{ NODE *ptr;
ptr=new NODE;
if(ptr= = NULL)
{
cout<<”\nNo memory to create a new node….”;
exit(1);
}
cout<<”\nEnter the Ticket Number….”;
cin>>ptr → Ticketno;
cout<<”\nEnter the Passenger Name..”;
gets(ptr → PName);
ptr → Next=NULL;
if(rear= = NULL)
front=rear=ptr;
else
{
rear → Next=ptr;
rear=ptr;
}
}

 

Previous Index Next

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