COMPUTER SCIENCE LINKED LISTS , STACKS AND QUEUES

3.c) Write a function in C++ to insert anelement into a dynamically allocated Queuewhere each node contains a name (of type string) as data. Assume the following definition of THENODE for the same.

struct THENODE
{
char Name[20];
THENODE *Link;
};
Solution:
struct THENODE
{
char Name[20];
THENODE *Link;
};
class Queue{
THENODE *front,*rear;
public:
Queue( )
{ front = rear = NULL; }
void Insert( );
void Delete( );
void Display( );
};
void Queue::Insert( )
{
THENODE *ptr;
ptr=new THENODE;
if(ptr= = NULL)
{
cout<<”\nNo memory to create a new node….”;
exit(1);
}
cout<<”\nEnter the name….”;
gets(ptr→ Name);
ptr→ Link=NULL;
if(rear= = NULL)
front=rear=ptr;
else
{
rear→ Link=ptr;
rear=ptr;
}
}

3.e) Evaluate the following postfix notation of expression (Show status of stack after execution of each operation ): 4, 10, 5, +, *, 15, 3, /, -

 

 

4

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_stack1.php on line 132

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_stack1.php on line 132

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

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_stack1.php on line 134