Idea Solution
#include<iostream.h>
#include<cstdlib>
#include<conio.h>
using namespace std;
struct node
{
string data;
int Age;
struct node *next;
};
class queue
{
public:
node *rear;
node *frnt;
queue()
{
frnt=rear=NULL;
}
void insert();
void del();
void show();
void display();
void length();
};
void queue::insert()
{
string namec;
int agec;
node *temp = new node;
cout"\nHow many node you want to create? : ";
cin>>namec;
cout"\nEEnter the name of node : ";
cin>>agec;
temp->data = namec;
temp->Age=agec;
temp->next = NULL;
if(frnt == NULL){
frnt = temp;
}else{
rear->next = temp;
}
rear = temp;
}
void queue::show()
{
node *ptr1=frnt;
if(frnt==NULL)
{
cout"The Queue is empty!!\n";
return;
}
else
{
cout"\nCustomer at the front is : "ptr1->data "\n";
}
}
void queue::del()
{
if(frnt==NULL)
{
cout"\nSorry. Queue is empty";
return;
}
node *temp;
temp=frnt;
frnt=frnt->next;
cout"\nCustomer removed/served successfully : "temp->data ;
delete temp;
}
void queue::length()
{
int x;
x=0;
node *ptr1=frnt;
while(ptr1!=NULL)
{
ptr1=ptr1->next;
x++;
}
cout"\nTHe customers are : " x ;
}
void queue::display()
{
node *ptr1=frnt;
if(frnt==NULL)
{
cout"The Queue is empty!!";
return;
}
cout"\nThe Queue is\n";
cout "Name Age \n";
while(ptr1!=NULL)
{
cout ptr1-> data ptr1->Age "\n" ;
ptr1=ptr1->next;
}
}
int main()
{
queue q;
char choice;
while(1)
{
cout "\n1- for Enter/adding nodes in Queue";
cout "\n2- for Remove/serve a nodes";
cout "\n3- for Show nodes at front ";
cout "\n4- for Display all nodes in queue";
cout "\n5- for Show size of Queue ";
cout "\n6- for Exit";
cout "\n\nEnter your option: ";
cin>>choice;
switch(choice)
{
case '1':
char check;
do
{
q.insert();
cout"\n Do u want to enter another nodes(y/n): ";
cin>>check;
}
while(check=='y' || check=='Y');
break;
case '2':
q.del();
break;
case '3':
q.show();
break;
case '4':
q.display();
break;
case '5':
q.length();
break;
case '6':
exit(0);
break;
default:
cout"\n Sorry characters are no allowed. Please enter only option 1-6!!\n";
break;
}}
return 0;}