forked from rituburman/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue_in_C++.cpp
More file actions
47 lines (45 loc) · 780 Bytes
/
Queue_in_C++.cpp
File metadata and controls
47 lines (45 loc) · 780 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
#include<bits/stdc++.h>
using namespace std;
#define MAX 5
int a[MAX],front=-1,rear=-1;
void push(int x){
if(rear==MAX-1){
cout<<"stack is overflow"<<endl;
}
else
{ rear=(rear+1)%MAX;
a[rear]=x;
if(front==-1)
front++;
}}
void pop()
{
if(front==-1){
cout<<"stack is underflow"<<endl;
}
else{
cout<<"deleted element is "<<a[front]<<endl;
if(front==rear){
front=rear=-1;
}
else
front=(front+1)%MAX;
}
}
void disp(){
cout<<"elements are"<<endl;
for(int i=front;i<=rear;i=(i+1)%MAX){
cout<<a[i]<<" ";
}
}
int main()
{
push(10);
push(20);
push(30);
disp();
pop();
pop();
disp();
return 0;
}