/*ALGORITHM:two ends
insertion:-at rear end frst check if array is empty to enter element nd if yes thn enter nd update rear
deletion:-at front end frst check if array has somethng to delte if yes delete nd update front
*/
#include<iostream>
#include<conio.h>
using namespace std;
struct player
{
char name[20];
player *next; //to store address of next piece of info(node) i.e which is at top of it
};
class queue
{
player *front,*rear;
public:
queue()
{
front=rear=NULL; //means queue is empty no node present(similar to static queue)
}
void ins();
void del();
void display();
};
void queue::ins()
{
player *temp=new player; //use it to store recent node for temporary tym nd assigned memory dynamically i.e at run time
if(temp==NULL)
{
cout<<"\nOVERFLOW ERROR..."<<endl;
return;
}
else
{
cout<<"ENTER PLAYER NAME:";
cin.ignore();
cin.getline(temp->name,20);
temp->next=NULL;
if(rear==NULL) //if ths is true thn it implies queue is empty nd now the upcoming node is bth front nd rear end (similar to static queue)
{
front=rear=temp;
}
else //if above condition is false thn it implies array alrady hve elements v jst need to store adddress of temp in current rear's next part to mke it part of queue nd thn make temp as rear
{
rear->next=temp;
rear=temp;
}
}
}
void queue::del()
{
player *temp;
if(front==NULL) //to check whther queue is empty(no element wud b there to delete) similar to static queue
{
cout<<"\nUNDERFLOW ERROR..."<<endl;
return;
}
else //here jst update front to currents front's next part address..like inn static queue v had 2 conditons here bth r met with ths only
{
temp=front;
cout<<temp->name<<" deleted";
front=front->next;
delete temp;
}

}
void queue::display()
{
for(player *temp=front;temp!=NULL;temp=temp->next)
cout<<"PLAYER NAME:"<<temp->name<<endl;
}
int main()
{
int choice;
char ans;
queue q;
do
{
cout<<"MENU:"<<endl
<<"1.INSERT"<<endl
<<"2.DELETE"<<endl
<<"3.DISPLAY"<<endl
<<"4.EXIT"<<endl<<endl;
cout<<"ENTER YOUR CHOICE:";
cin>>choice;
switch(choice)
{
case 1:
q.ins();
break;
case 2:
q.del();
break;
case 3:
q.display();
break;
case 4:
exit(0);
}
cout<<"\nDO YOU WANT TO GO BACK TO MAIN MENU:";
cin>>ans;
}while(ans!='n');

getch();
return 0;
}


USERS VISITED
http://www.hitwebcounter.com/