-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.hpp
More file actions
78 lines (66 loc) · 1.15 KB
/
queue.hpp
File metadata and controls
78 lines (66 loc) · 1.15 KB
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
#pragma once
#include <iostream>
#include "datatype.hpp"
using namespace std;
class Heap_Node
{
public:
float data;
Course* node;
Heap_Node* LeftChild;
Heap_Node* RightChild;
Heap_Node* Parent;
Heap_Node(float value)
{
data = value;
LeftChild = NULL;
RightChild = NULL;
Parent = NULL;
}
};
struct QNode {
Heap_Node* data;
QNode* next;
QNode(Heap_Node* d)
{
data = d;
next = NULL;
}
};
class Queue {
private:
QNode* Front, * rear;
public:
Queue()
{
Front = rear = NULL;
}
bool is_empty()
{
return (Front == NULL) ;
}
Heap_Node* front()
{
return Front->data;
}
void push(Heap_Node* x)
{
QNode* temp = new QNode(x);
if (rear == NULL) {
Front = rear = temp;
return;
}
rear->next = temp;
rear = temp;
}
void pop()
{
if (Front == NULL)
return;
QNode* temp = Front;
Front = Front->next;
if (Front == NULL)
rear = NULL;
delete (temp);
}
};