-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue_array.cpp
More file actions
118 lines (92 loc) · 2.27 KB
/
Copy pathqueue_array.cpp
File metadata and controls
118 lines (92 loc) · 2.27 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// g++ queue_array.cpp -o queue_array && ./queue_array
// WRITE COMMENT HERE
/*
*/
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << " " << x << endl;
#define ll long long
class queue_array{
private:
int size = 50;
int f = -1,r = -1;
int arr[50];
public:
void enqueue(int num){
(f++)%(size-1);
arr[f] = num;
}
int dequeue(){
if(r == f) cout << "Queue is empty ";
else{
(r++)%(size-1);
int temp = arr[r];
return temp;
}
return -1;
}
int front(){
if(f != r) return arr[f];
}
int rare(){
if(f != r) return arr[r];
}
bool isEmpty(){
if(f != r) return false;
else return true;
}
};
class queue_ll{
private:
struct node {
int data;
struct node* next;
};
struct node *f = NULL;
struct node *r = NULL;
public:
void enqueue(int num){
node* temp = new node();
temp->data = num;
temp->next = NULL;
if(f == NULL){
f = r = temp;
}
else{
r->next = temp;
r = temp;
}
}
int dequeue(){
if(f == NULL) cout << "Queue is empty ";
else{
int temp = f->data;
f = f->next;
return temp;
}
return -1;
}
int front(){
if(f != NULL) return f->data;
else cout << "queue is empty" << endl;
}
int rare(){
if(f != NULL) return r->data;
}
bool isEmpty(){
if(f != NULL) return false;
else return true;
}
};
int main(){
queue_array *qa = new queue_array();
queue_ll *ql = new queue_ll();
for(int i = 0; i < 10; i++){
qa->enqueue(i);
ql->enqueue(i);
}
cout << "queue array :";
for(int i = 0; i < 10; i++) cout << qa->dequeue() << " "; cout << endl;
cout << "queue ll :";
for(int i = 0; i < 10; i++) cout << ql->dequeue() << " "; cout << endl;
}