-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.cpp
More file actions
100 lines (77 loc) · 1.92 KB
/
check.cpp
File metadata and controls
100 lines (77 loc) · 1.92 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
#include<iostream>
using namespace std;
struct QueueNode{
char data;
QueueNode* next;
QueueNode(char d ='\0' , QueueNode* nxt = NULL){
data = d;
next = nxt;
}
};
class Queue{
public:
QueueNode* front;
QueueNode* rear;
Queue(QueueNode* f =NULL , QueueNode* r = NULL){
front = f;
rear = r;
}
void enqueue(char add){
if(isEmpty() == true){
front = new QueueNode(add);
rear = front;
return;
}
rear->next = new QueueNode(add);
rear = rear->next;
}
char dequeue(){
if(isEmpty() == true){
cout<<"QUEUE IS EMPTY \n";
return '\0';
}
QueueNode* temp = front;
front = front->next;
if(front == NULL){
rear = NULL;
}
char ch = temp->data;
delete temp;
return ch;
}
bool isEmpty(){
return front == NULL && rear == NULL;
}
void display(){
if (isEmpty()) {
cout << "QUEUE IS EMPTY" << endl;
return;
}
QueueNode* temp = front;
while(temp != rear){
cout << temp->data;
temp = temp->next;
}
cout << rear->data << endl;
}
void makeEmpty(){
while(!isEmpty()){
dequeue();
}
}
};
int main() {
Queue q;
q.enqueue('A');
q.enqueue('B');
q.enqueue('C');
cout << "Queue after enqueuing A, B, C: ";
q.display();
cout << "Dequeued element: " << q.dequeue() << endl;
cout << "Queue after dequeuing one element: ";
q.display();
q.MAKEeMPTY();
cout << "Queue after making empty: ";
q.display();
return 0;
}