-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue and its operation.cpp
More file actions
75 lines (66 loc) · 871 Bytes
/
queue and its operation.cpp
File metadata and controls
75 lines (66 loc) · 871 Bytes
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
#include<bits/stdc++.h>
using namespace std;
int rear = -1;
int front = -1;
int size = 10;
int q[10];
int isempty()
{
if(front&&rear == -1)
{
return -1;
}
else{
return 0;
}
}
int isfull()
{
if(rear == size)
{
return -1;
}
else{
return 0;
}
}
void enqueue(int data)
{
if(!isfull())
{
rear&&front == 1;
q[rear] = data;
}
rear++;
}
void dequeue()
{
if(!isempty())
{
front = q[front];
}
front++;
}
void display()
{
cout<<"queue is as follows: "<<endl;
for(int i = front; i<rear; i++)
{
cout<<q[i]<<" ";
}
cout<<endl;
}
int main()
{
enqueue(10);
enqueue(20);
enqueue(30);
enqueue(40);
enqueue(50);
enqueue(60);
display();
dequeue();
dequeue();
display();
return 0;
}