-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.cpp
54 lines (54 loc) · 1.1 KB
/
Queue.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
#include "Node.cpp"
#include <iostream>
using namespace std;
class Queue
{
private:
OneWayNode *first = nullptr;
public:
void Enqueue(OneWayNode *node)
{
if (node)
{
if (!first)
{
first = node;
}
else
{
OneWayNode *active = first;
while (active->next)
{
active = active->next;
}
active->next = node;
}
}
}
OneWayNode *Pop()
{
if (first)
{
OneWayNode *result = first;
first = first->next;
return result;
}
else
return nullptr;
}
Queue() {}
~Queue() {}
};
int main()
{
Queue *q = new Queue();
q->Enqueue(new OneWayNode(1));
q->Enqueue(new OneWayNode(2));
q->Enqueue(new OneWayNode(3));
q->Enqueue(new OneWayNode(4));
cout << q->Pop()->data << endl;
cout << q->Pop()->data << endl;
cout << q->Pop()->data << endl;
cout << q->Pop()->data << endl;
return 0;
}