-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7queue.cpp
More file actions
100 lines (99 loc) · 1.92 KB
/
Copy path7queue.cpp
File metadata and controls
100 lines (99 loc) · 1.92 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include <climits>
#define MAX 10
using namespace std;
class queue
{
private:
int arr[MAX], front, rear;
public:
queue()
{
front = -1;
rear = -1;
}
bool isEmpty()
{
return front == rear;
}
bool isFull()
{
return rear == MAX - 1;
}
void enqueue(int k)
{
if (isFull())
{
cout << "queue is full";
return;
}
arr[++rear] = k;
}
int dequeue()
{
int a;
if (isEmpty())
return INT_MIN;
front = front + 1;
return arr[front];
if (front == MAX)
return INT_MAX;
}
int peek()
{
if (isEmpty())
return INT_MIN;
return arr[front + 1];
}
void display()
{
if (isEmpty())
{
cout << "nothing is in stack\n";
return;
}
for (int i = front + 1; i <= rear; i++)
cout << arr[i] << " ";
cout << "\n";
}
};
int main()
{
queue s1;
int i = 0;
cout << "to enqueue an integer type 1\n"
<< "to dequeue an integer type 2\n"
<< "to peak an integer type 3\n"
<< "to display stack type 4\n"
<< "to stop the stack type 5\n";
while (i != 5)
{
cin >> i;
switch (i)
{
case 1:
int a;
cin >> a;
s1.enqueue(a);
cout << "enqueue " << a << "\n";
break;
case 2:
cout << "popped integer: " << s1.dequeue() << "\n";
break;
case 3:
cout << "peeked front: ";
cout << s1.peek() << "\n";
break;
case 4:
s1.display();
break;
case 5:
cout << "exit";
break;
default:
cout << "input Not found\n";
break;
}
}
return 0;
}