COMPUTER SCIENCE LINKED LISTS , STACKS AND QUEUES

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

 

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( mrkdata@yahoo.com )


Warning: include_once(../../ebooks-footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/linklist_stack8.php on line 126

Warning: include_once(): Failed opening '../../ebooks-footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/linklist_stack8.php on line 126

Warning: include_once(../../../footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/linklist_stack8.php on line 128

Warning: include_once(): Failed opening '../../../footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/linklist_stack8.php on line 128