3 (e) Give the necessary declaration of a
linked list implemented queue containing
float type elements. Also write a user defined
function in C++ to delete a float type number from the queue.
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 → next;
delete temp;
}
}
1998:
3 (d) Evaluate the following postfix expression using a stack and show the contents of stack after execution of each
operation: 50, 40, +, 18, 14, -, 4, *, +
Ans) Children, Try this answer as an
assignment.
3 (e) Give the necessary declaration of a
linked implemented stack containing integer type numbers; also write a user defined function in C++ to pop a number from this stack.
Solution:
struct Node
{ float Number;
Node *Next ;
} ;
class Stack
{ Node *Top;
public:
Stack( )
{ Top = NULL; }
void Push( );
void Pop( );
void Display( );
};
void Stack::Pop( )
{ Node *Temp;
If( Top= = NULL)
cout<<”Stack Underflow…”;
else
{ cout<<”\nThe Number of the element to delete: “<<Top → Number;
Temp=Top;
Top=Top → Next;
Delete Temp;
} }
CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )