COMPUTER SCIENCE LINKED LISTS , STACKS AND QUEUES

3.e) Define member functions queins( ) to insert nodes and quedel ( ) to delete nodes of the linked list implemented class queue, where each node has the following structure:

struct node
{ char name[20] ;
int age ;
node *Link ;
} ;
class queue
{ node *rear, *front ;
public :
queue( ) { rear = NULL;
front = NULL} ;
void queins( ) ;
void quedel( ) ;
} ;

Solution:

void queue::queins( )
{ node *ptr;
ptr=new node;
if(ptr= = NULL)
{
cout<<”\nNo memory to create a new node….”;
exit(1);
}
cout<<”\nEnter the name….”;
gets(ptr → name);
cout<<”\nEnter the age…”;
cin>>ptr → age;
ptr → Link=NULL;
if(rear= = NULL)
front=rear=ptr;
else
{
rear → Link=ptr;
rear=ptr;
}
}
void queue::quedel( )
{ node *temp;
if(front= = NULL)
cout<<”Queue Underflow”;
else
{ cout<<”\nThe name of the element to delete: “<<front → name;
cout<<”\nThe age of the element to delete: “<<front → age;
temp=front;
front=front → Link;
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_stack7.php on line 123

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_stack7.php on line 123

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

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_stack7.php on line 125