COMPUTER SCIENCE LINKED LISTS , STACKS AND QUEUES

DELHI : 2000

3.d) Evaluate the following postfix expression using a stack. Show the contents of stack after execution of each operation: 20, 8, 4, /, 2, 3, +, *, -

Ans) Children, Try this answer as an assignment.

3.e) Give necessary declarations for a queue containing float type numbers; also write a user defined function in C++ to insert a float type number in the queue. You should use linked representation of queue.

Solution:

struct NODE
{ float Number;
NODE *Link;
};
class Queue
{ NODE *front,*rear;
public:
Queue( )
{ front = rear = NULL; }
void Insert( );
void Delete( );
void Display( );
};
void Queue::Insert( ){
NODE *ptr;
ptr=new NODE;
if(ptr= = NULL)
{
cout<<”\nNo memory to create a new node….”;
exit(1);
}
cout<<”\nEnter the Number….”;
cin>>ptr → Number;
ptr → Link=NULL;
if(rear= = NULL)
front=rear=ptr;
else
{
rear → Link=ptr;
rear=ptr;
}
}

1999:

3 (d) Evaluate the following postfix expression using a stack and show the contents of the stack after execution of each operation 5,11,-,6,8,+,12,*,/

Ans) Children, Try this answer as an assignment.

 

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