COMPUTER SCIENCE LINKED LISTS , STACKS AND QUEUES

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 ( 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_stack12.php on line 147

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_stack12.php on line 147

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

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_stack12.php on line 149