-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.txt
69 lines (69 loc) · 985 Bytes
/
queue.txt
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
///BISMILLAHIR RAHMANIR RAHIM///
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define n 5
int front=-1,rear=-1;
int a[n];
void enqueue(int x)
{
if(rear==n-1)
cout<<"Overflow"<<endl;
else if(front==-1&&rear==-1)
{
front=0;
rear=0;
a[rear]=x;
}
else
{
rear++;
a[rear]=x;
}
}
void dequeue()
{
if(front==-1)
cout<<"Underflow"<<endl;
else if(front==rear)
{
front=rear=-1;
}
else
{
cout<<a[front]<<endl;
front++;
}
}
void s_top()
{
if(front==-1)
cout<<"Underflow"<<endl;
else
{
cout<<a[front]<<endl;
front++;
}
}
void show()
{
if(front==-1)
cout<<"Underflow"<<endl;
else
{
for(int i=front;i<=rear;i++)
cout<<a[i]<<" ";
cout<<endl;
}
}
int main()
{
enqueue(2);
enqueue(3);
enqueue(4);
show();
dequeue();
s_top();
show();
return 0;
}