-
Notifications
You must be signed in to change notification settings - Fork 86
/
circularqueues.cpp
72 lines (55 loc) · 842 Bytes
/
circularqueues.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
#include<iostream>
using namespace std;
class CQNode{
public:
int data;
CQNode *next;
CQNode(int d){
data=d;
next=NULL;
}
};
class CQ{
public:
CQNode *Front;
CQ(){
Front=NULL;
}
void Insert(int value){
CQNode *cq= new CQNode(value);
if(Front==NULL)
{
Front=cq;
Front->next=Front;
}
else
{
CQNode *ptr=Front;
for(ptr=Front;ptr->next!=Front;ptr=ptr->next)
;
ptr->next=cq;
cq->next=Front;
}
}
void Display(){
CQNode *ptr=Front;
if(Front==NULL){
cout<<"\nEmpty Queues.\n";
return;
}
for(ptr=Front;ptr->next!=Front;ptr=ptr->next)
{
cout<<ptr->data<<" ";
}
cout<<ptr->data;
cout<<endl;
}
};
int main()
{
CQ q;
q.Insert(4);
// q.Insert(5);
q.Display();
return 0;
}