-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharray_based_queue.cpp
More file actions
72 lines (64 loc) · 1.22 KB
/
Copy patharray_based_queue.cpp
File metadata and controls
72 lines (64 loc) · 1.22 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
#include <iostream>
using namespace std;
class Queue{
public:
int arr[1000];
int top,rear,len;
Queue(){
top = -1;
rear = -1;
len = -1;
}
void enque(int x){
if(len == -1){ top++;}
rear ++;
arr[rear] = x;
len ++;
}
void deque(){
if(len==-1){cout << "Not possible as lenght of queue = 0" << endl; return;}
top ++;
len --;
}
int lens(){
cout << "the length of queue is " << len+1 << endl;
return len+1;
}
int front(){
if(len==-1){cout << "empty queue " << endl; return NULL;}
cout << "the front element of the queue is " << arr[rear] << endl;
return arr[rear];
}
void print(){
if(len==-1){cout << "empty queue " << endl; return;}
cout << "the left element is the first element of the queue" << endl;
for(int i=top;i<=rear;i++){
cout << arr[i] << endl;
}
}
};
int main(){
int n;
cout << "enter the number of elements of Queue" << endl;
cin >> n;
Queue q;
for(int i=0;i<n;i++){
cout << "enter it" << endl;
int k;
cin >> k ;
q.enque(k);
}
q.front();
q.print();
q.lens();
q.deque();
q.print();
q.lens();
q.deque();
q.deque();
q.deque();
q.deque();
q.print();
q.lens();
q.deque();
}