-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.cpp
81 lines (73 loc) · 1.12 KB
/
queue.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
#include<iostream>
using namespace std;
class queue
{
private:
int q[10];
int front,rear,max;
public:
queue();
void insert();
void remove();
int &operator[](int rear){
if(rear>max)
{
cout<<"index out of bounds";
}
}
void display();
};
queue::queue()
{
front=rear=-1;
cout<<"enter no. of elemnts";
cin>>max;
}
void queue::insert()
{
int n;
if (rear == max - 1){
printf("Queue Overflow \n");
}
else
{
if (front == -1){
front = 0;}
cout<<"inset the element in queue : ";
cin>>n;
rear = rear + 1;
q[rear] = n;
}
}
void queue::remove()
{
cout<<"deleted element is"<<q[rear];
q[--rear];
}
void queue::display()
{
cout << "Value of q[2] : " << q[2] <<endl;
cout << "Value of q[5] : " << q[5]<<endl;
cout << "Value of q[12] : " << q[12]<<endl;
}
int main()
{
queue a;
int i,c;
do
{
cout<<"choose option 1.insert 2.delete";
cin>>c;
if(c==1)
{
a.insert();
}
else
{
a.remove();
}
cout<<"do you want to continue";
cin>>i;
}while(i==1);
a.display();
}