-
Notifications
You must be signed in to change notification settings - Fork 7
/
49_Circular_Queue_LinkedList.cpp
76 lines (72 loc) · 1.58 KB
/
49_Circular_Queue_LinkedList.cpp
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
#include<iostream>
using namespace std;
class Node{
public:
int data;
Node *next=NULL;
Node(int data){
this->data = data;
this->next = NULL;
}
};
class Queue{
Node *front;
Node *rear;
public:
Queue(int data){
Node *newnode = new Node(data);
front = newnode;
rear = newnode;
}
Queue(){
front = NULL;
rear = NULL;
}
void enQueue(int data){
Node *newnode = new Node(data);
if(front==NULL && rear == NULL){
front=rear=newnode;
return;
}
rear->next = newnode;
rear = newnode;
rear->next = front;
}
void deQueue(){
if(front==NULL){
cout<<"Stack is empty"<<endl;
return;
}
Node *temp =front;
front = front->next;
rear->next = front;
delete temp;
}
void Display(){
if(front==NULL){
cout<<"Queue is Empty"<<endl;
return;
}
Node* temp = front;
while(temp!=rear){
cout<<temp->data<<"->";
temp = temp->next;
}
cout<<rear->data<<endl;
return;
}
};
int main()
{
Queue q1(10);
q1.Display();
q1.enQueue(15);
q1.enQueue(20);
q1.enQueue(30);
q1.Display();
q1.deQueue();
q1.Display();
q1.deQueue();
q1.Display();
return 0;
}