1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <iostream>
using namespace std;
struct Node
{
int data;
Node *next;
};
void createNodes(int nodesize,Node *head,Node *tail,Node *temp);
void add(int push,Node *head,Node *tail,Node *temp);
int main()
{
Node *ptr,*head,*tail,*temp;
int choice,nodesize,push;
cout<<"What is the size of the queue?: ";
cin>>nodesize;
createNodes(nodesize,head,tail,temp);
do
{
cout<<"Options"<<endl;
cout<<"1.)Add"<<endl;
cout<<"2.)Delete"<<endl;
cout<<"3.)Exit"<<endl;
cout<<"Choice: ";
cin>>choice;
if(choice==1)
{
cout<<"Enter the number to be added: ";
cin>>push;
add(push,head,tail,temp);
}
if(choice==4)
{
temp=head;
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
}
}while(choice!=3);
return 0;
}
void createNodes(int nodesize,Node *head,Node *tail,Node *temp)
{
Node *ptr;
for(int x=0;x<nodesize;x++)
{
if(x==0)
{
ptr=new Node;
ptr->next=NULL;
ptr->data=0;
head=ptr;
temp=head;
}
else
{
ptr=new Node;
ptr->next=NULL;
ptr->data=0;
tail=ptr;
temp->next=ptr;
temp=ptr;
}
}
}
void add(int push,Node *head,Node *tail,Node *temp)
{
temp=head;
while(temp!=NULL)
{
if(temp->data==0)
{
temp->data=push;
break;
}
if(temp->next==NULL&&temp->data!=0)
{
cout<<"Queue OverFlow!"<<endl;
}
temp=temp->next;
}
}
|