3.e) Evaluate the following postfix notation of
expression : 25 8 3 - / 6 * 10 + (2)
Ans) Children, Try this answer as an assignment.
OUTSIDE DELHI : 2007
3.c) Write a function in C++ to delete a node
containing customer’s information, from a dynamically allocated Queue of Customers
implemented with the help of the following structure:
struct Customer
{ int CNo ;
char CName[20] ;
Customer *Link ;
} ;
Solution: struct Customer
{ int CNo ;
char CName[20] ;
Customer *Link ;
} ;
class Queue
{ Customer *front,*rear;
public:
Queue( )
{ front=rear=NULL; }
void Insert( );
void Delete( );
void Display( );
};
void Queue::Delete( )
{ Customer *Temp;
if(front= =NULL)
cout<<”Queue Underflow. No element to delete”;
else
{ cout<<”\n The customer number for the element to delete”<<front → CNo;
cout<<”\n The customer name for the element to delete”<<front → CName;
Temp=front;
front = front → Link;
delete Temp;
}
}
3.e) Evaluate the following postfix notation of expression : 15 3 2 + / 7 + 2. * .
2
Ans) Children, Try this answer as an
assignment.
DELHI : 2006
3.c )
class queue
{ int data[10] ;
int front, rear ;
public :
queue( ) { front = - 1 ; rear = - 1 ; }
void add( ) ; //to add an element into the queue
void remove( ) ; //to remove an element from the queue
void Delete(int ITEM( ) ; //to delete all elements which are equal to ITEM
} ;
Complete the class with all function
definitions for a circular array Queue. Use+
another queue to transfer data temporarily.
Solution:
void queue::add( )
{ if((front= = 0 && rear = = 9) | | (front= =rear+1)
cout<<”\nQueue
Overflow”;
else if (rear= = -1)
{ front=rear=0;
cout<<”\nEnter the element to be inserted”;
cin>>data[rear];
}
else if(rear= =9)
{ rear=0;
cout<<”\nEnter the element to be inserted”;
cin>>data[rear];
}
else
{ rear++;
cout<<”\nEnter the element to be inserted”;
cin>>data[rear];
}
}
void queue::remove( )
{ if(front= = -1)
cout<<”\nQueue Underflow…”;
else
{ cout<<”\nThe element to be deleted”<<data[front];
if(front= =rear)
front=rear=-1;
else if (front= =9)
front=0;
else
front++;
}
}
void queue::Delete(int ITEM )
{
//Children, try to complete this function.}
CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )