forked from rigtorp/SPSCQueue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimplestdynamicqueue.cpp
More file actions
84 lines (80 loc) · 1.04 KB
/
Simplestdynamicqueue.cpp
File metadata and controls
84 lines (80 loc) · 1.04 KB
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
#include<iostream>
using namespace std;
struct node
{
int info;
node*ptr;
};
node*insert(node *rear)
{
node*temp=NULL;
temp=new node;
cout<<"Enter the information\n";
cin>>temp->info;
temp->ptr=NULL;
if(rear==NULL)
{rear=temp;
}
else
{rear->ptr=temp;
rear=temp;
}
return rear;
}
node*del (node *front)
{
node*temp=NULL;
temp=front;
if(front!=NULL)
{front=front->ptr;
delete temp;
}
else
cout<<"Queue underflow\n";
return front;;
}
void disp(node *front)
{
node*temp=front;
if(temp==NULL)
{cout<<"empty stack\n";
}
while(temp!=NULL)
{
cout<<temp->info;
temp=temp->ptr;
cout<<"\n";
}
}
main()
{
int s[25];
int n=25;
node *front=NULL;
node *rear=NULL;
int x=0;
char ans='y';
while(ans=='y')
{
do
{
cout<<"1 to insert elements\n";
cout<<"2 to delete elements\n";
cout<<"3 to display stack\n";
cin>>x;
}
while(x>3 && x<0);
switch(x)
{
case 1:rear=insert(rear);
if(front==NULL)
front=rear;break;
case 2:front=del(front);
if(front==NULL)
rear=front;break;
case 3:disp(front);break;
}
cout<<"Do you want to run again (Enter y to continue)\n";
cin>>ans;
}
}