in want to edit the code in such a way tht the user can enter upto 10 values maximum..need help pls ...
#include <iostream>
#include <iomanip>
using namespace std;
struct node
{
int info;
struct node* next;
}*front,*rear;
void enqueue(int elt);
int dequeue();
void display();
void main()
{
int ch,elt;
rear=NULL;
front=NULL;
while(1)
{
cout<<"Enter:\t1->Insert\t2->Delete\t3->Display\t4->Exit\n";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter The Values: ";
cin>>elt;
enqueue(elt);
break;
case 2:
elt=dequeue();
cout<<"The deleted value = "<<elt<<"\n";
break;
case 3:
display();
cout<<"\n";
break;
default:
cout<<"~~~Exit~~~";
cin.get();cin.get();
exit(0);
break;
}
}
}
void enqueue(int elt)
{
struct node *p;
p=(struct node*)malloc(sizeof(struct node));
p->info=elt;
p->next=NULL;
if(rear==NULL||front==NULL)
front=p;
else
rear->next=p;
rear=p;
}
int dequeue()
{
struct node *p;
int elt;
if(front==NULL||rear==NULL)
{
cout<<"\nThe Queue is empty. Cannot delete further.";
cin.get();cin.get();
exit(0);
}
else
{
p=front;
elt=p->info;
front=front->next;
free(p);
}
return(elt);
}
void display()
{
struct node *t;
t=front;
while(front==NULL||rear==NULL)
{
cout<<"\nQueue is empty";
cin.get();cin.get();
exit(0);
}
cout<<"The numbers in the queue are-->";
while(t!=NULL)
{
cout<<t->info<<"\t";
t=t->next;
}
}