forked from ambujraj/hacktoberfest2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueueMenu.cpp
155 lines (128 loc) · 4.53 KB
/
QueueMenu.cpp
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream>
#define max 10
using namespace std;
struct queue
{
int data[max];
int head;
int tail;
};
queue antrian;
void create()
{
antrian.head=antrian.tail=-1;
}
int isempty()
{
if(antrian.tail==-1) return 1;
else return 0;
}
int isfull()
{
if(antrian.tail==max-1) return 1;
else return 0;
}
void enqueue(int data)
{
if(isempty()==1)
{
antrian.head=antrian.tail=0;
antrian.data[antrian.tail]=data;
cout<<antrian.data[antrian.tail]<<" added !"<<endl;
}
else
{
if(isfull()==0)
{
antrian.tail++;
antrian.data[antrian.tail]=data;
cout<<antrian.data[antrian.tail]<<" added !"<<endl;
}
}
}
int dequeue()
{
int e = antrian.data[antrian.head];
for(int i = antrian.head; i<=antrian.tail-1;i++)
{
antrian.data[i] = antrian.data[i+1];
}
antrian.tail--;
return e;
}
void tampil()
{
if(isempty()==0)
{
for(int i=antrian.head;i<=antrian.tail;i++)
{
cout<<"Number : "<<antrian.data[i]<<endl;
}
}
else
{
cout<<"no data"<<endl;
}
}
void clear()
{
antrian.head=antrian.tail=-1;
cout<<"data clear\n";
}
int main()
{
int opt, angka;
create();
do
{
system("cls");
cout<<" Queue Program \n";
cout<<" ===============================\n";
cout<<" = 1. Enqueue =\n";
cout<<" = 2. Dequeue =\n";
cout<<" = 3. Show =\n";
cout<<" = 4. Clear All =\n";
cout<<" = 5. Exit =\n";
cout<<" ===============================\n\n";
cout<<" Enter your choice : "; cin>>opt;
switch(opt)
{
case 1: system("cls");
{
cout<<"Number : ";
cin>>angka;
enqueue(angka);
break;
}
case 2: system("cls");
{
cout<<dequeue()<<" removed";
break;
}
case 3: system("cls");
{
tampil();
break;
}
case 4: system("cls");
{
clear();
break;
}
case 5: system("cls");
{
cout<<"Created by Alvin Tandiardi";
return 0;
}
default : system ("cls");
{
cout<<"\n Sorry, Your choice not available\n\n";
break;
}
}
cout<<endl;
system("pause");
}
while(opt!=5);
return 0;
}