Skip to content

Commit 75c2416

Browse files
committed
📦 NEW: queue
1 parent e8259a1 commit 75c2416

File tree

3 files changed

+143
-1
lines changed

3 files changed

+143
-1
lines changed

‎Queue/Queue.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#include <iostream>
2-
#include "node.cpp"
32
#include "cStack.cpp"
43
using namespace std;
54

65
class cQue : protected cStack
76
{
87
cNode *tail;
8+
9+
public:
910
cQue() : tail(NULL) {}
1011

1112
cQue(cNode *&ptr) : cStack(ptr)
@@ -50,7 +51,10 @@ class cQue : protected cStack
5051
tail = tail->next;
5152
}
5253
else
54+
{
5355
tail = top = ptr;
56+
cout << "hello ";
57+
}
5458

5559
tail->next = NULL;
5660
ptr = NULL;
@@ -61,4 +65,16 @@ class cQue : protected cStack
6165
{
6266
cStack::print();
6367
}
68+
69+
cQue &operator=(const cStack &robj)
70+
{
71+
if (this == &robj)
72+
return *this;
73+
if (true)
74+
{
75+
cQue temp;
76+
temp.top = top;
77+
temp.tail = tail;
78+
}
79+
}
6480
};

‎Queue/main.cpp

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#include <iostream>
2+
#include "Queue.cpp"
3+
using namespace std;
4+
5+
int main()
6+
{
7+
cQue queue;
8+
/*
9+
This is a check to see if the Queue is empty by using isEmpty function
10+
*/
11+
cout << "This is a check to see if the Queue is empty by using isEmpty function. " << endl;
12+
if (queue.isEmpty())
13+
{
14+
cout << "Queue is empty." << endl
15+
<< endl;
16+
}
17+
else
18+
{
19+
cout << "Queue is not Empty." << endl
20+
<< endl;
21+
}
22+
23+
/*
24+
This is a check to see if the Queue is empty by using isEmpty function.
25+
*/
26+
cout << "This is a check to see if the Queue is empty by using isEmpty function." << endl;
27+
if (queue.isNotEmpty())
28+
{
29+
cout << "Queue is not empty." << endl
30+
<< endl;
31+
}
32+
else
33+
{
34+
cout << "Queue is Empty." << endl
35+
<< endl;
36+
}
37+
38+
/*
39+
This is a check to see all the elements present in the queue by printing them.
40+
*/
41+
cout << "This is a check to see all the elements present in the queue by printing them." << endl;
42+
queue.print();
43+
cout << endl;
44+
45+
/*
46+
Declaring a node and setting the data
47+
*/
48+
cNode *ptr = new cNode(102);
49+
/*
50+
Pushing the new node into the Queue whose address is stored in ptr into the Queue
51+
*/
52+
queue.add(ptr);
53+
54+
/*
55+
This is a check to see if the Queue is empty or not using empty function.
56+
*/
57+
cout << "This is a check to see if the Queue is empty or not using empty function." << endl;
58+
if (queue.isEmpty())
59+
{
60+
cout << "Queue is empty." << endl;
61+
}
62+
else
63+
{
64+
cout << "Queue is not Empty." << endl
65+
<< endl;
66+
}
67+
68+
/*
69+
Now printing the data present in the Queue
70+
*/
71+
cout << "Printing the data present in the Queue using print function." << endl;
72+
queue.print();
73+
74+
/*
75+
Deleting the latest node from the Queue using remove function when only one node is present in the Queue
76+
*/
77+
queue.remove();
78+
/*
79+
After Deleting first latest node from Queue, printing the Queue
80+
*/
81+
cout << "After Deleting latest node from Queue, printing all the data in the Queue." << endl;
82+
queue.print();
83+
84+
/*
85+
Now iniializing a node and setting data using setData fuction.
86+
*/
87+
cNode *newNode = new cNode();
88+
newNode->setData(431);
89+
queue.add(newNode);
90+
cout << "\nNow iniializing a node and setting data using setData function. " << endl;
91+
queue.print();
92+
/*
93+
Now declaring few more nodes and setting data using set Data function and pushing them to queue
94+
*/
95+
96+
cNode *node2 = new cNode();
97+
node2->setData(324);
98+
queue.add(node2);
99+
100+
cNode *node3 = new cNode();
101+
node3->setData(235);
102+
queue.add(node3);
103+
104+
cNode *node4 = new cNode();
105+
node4->setData(833);
106+
queue.add(node4);
107+
108+
cNode *node5 = new cNode();
109+
node5->setData(424);
110+
queue.add(node5);
111+
112+
cNode *node6 = new cNode();
113+
node6->setData(145);
114+
queue.add(node6);
115+
116+
cNode *node7 = new cNode();
117+
node7->setData(524);
118+
queue.add(node7);
119+
120+
/*
121+
Now Queue will be returned if isNotEmpty function returns true.
122+
*/
123+
cout << "\n\nNow Queue will be printed if isNotEmpty function returns true." << endl;
124+
if (queue.isNotEmpty())
125+
queue.print();
126+
}

‎Queue/main.exe

40.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)