Skip to content

Commit 474e841

Browse files
queueusingclass.cpp
A queue data structure implementation using class.
1 parent cf4f18d commit 474e841

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

Queue/queueusingclass.cpp

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include <iostream>
2+
#define MAX 10
3+
4+
using namespace std;
5+
6+
class Queue
7+
{
8+
int front,rear;
9+
int queue[MAX];
10+
//int item;
11+
12+
public:
13+
14+
Queue()
15+
{
16+
front=rear=-1;
17+
}
18+
19+
void qinsert(int item)
20+
{
21+
if(rear==MAX-1)
22+
{
23+
cout<<"\nQUEUE OVERFLOW";
24+
}
25+
else if(front==-1 && rear==-1)
26+
{
27+
front=rear=0;
28+
// cin>>item;
29+
queue[rear]=item;
30+
cout<<"\nITEM INSERTED: "<<item;
31+
}
32+
else
33+
{
34+
rear++;
35+
queue[rear]=item;
36+
cout<<"\nITEM INSERTED: "<<item;
37+
}
38+
}
39+
40+
void qdelete()
41+
{
42+
int item;
43+
44+
if(rear==-1)
45+
{
46+
cout<<"\nQUEUE UNDERFLOW";
47+
}
48+
else if(front==0 && rear==0)
49+
{
50+
item=queue[front];
51+
front=rear=-1;
52+
cout<<"\n\nITEM DELETED: "<<item;
53+
}
54+
else
55+
{
56+
item=queue[front];
57+
front++;
58+
cout<<"\n\nITEM DELETED: "<<item;
59+
}
60+
}
61+
62+
void qtraverse()
63+
{
64+
if(front==-1)
65+
{
66+
cout<<"\n\nQUEUE IS EMPTY\n";
67+
}
68+
else
69+
{
70+
cout<<"\n\nQUEUE ITEMS\n";
71+
for(int i=front;i<=rear;i++)
72+
{
73+
cout<<queue[i]<<" ";
74+
}
75+
cout<<endl;
76+
}
77+
}
78+
};
79+
80+
int main()
81+
{
82+
Queue q;
83+
84+
q.qtraverse();
85+
q.qinsert(10);
86+
q.qinsert(25);
87+
88+
q.qtraverse();
89+
90+
q.qdelete();
91+
q.qinsert(30);
92+
93+
q.qtraverse();
94+
return 0;
95+
}

0 commit comments

Comments
 (0)