-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest2.cpp
More file actions
98 lines (80 loc) · 1.72 KB
/
test2.cpp
File metadata and controls
98 lines (80 loc) · 1.72 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// main.cpp
// test
//
// Created by KevinLiu on 16/12/13.
// Copyright © 2016年 KevinLiu. All rights reserved.
//
//test for Heap
#include <iostream>
#include <string>
#include "Heap.hpp"
using namespace std;
int main()
{
Heap<string> heap1;
heap1.add("Gerge");
heap1.add("Michael");
heap1.add("Tom");
heap1.add("Adam");
heap1.add("Jones");
heap1.add("Peter");
while (heap1.getsize() > 0)
{
cout << heap1.remove() << " ";
}
cout << endl;
int number[] = {8,9,2,3,4,1,5,6,7};
Heap<int> heap2(number,9);
while(heap2.getsize() > 0)
cout << heap2.remove()<<" ";
cout << endl;
return 0;
}
//test for priority queue
#include <iostream>
#include <string>
#include "Heap.hpp"
using namespace std;
class Patient
{
string name;
int priority;
public:
Patient(string name,int prio)
{
this->name = name;
this->priority = prio;
}
bool operator<(Patient &rhs)
{
return (this->priority < rhs.priority);
}
bool operator>(Patient &rhs)
{
return (this->priority > rhs.priority);
}
string getName()
{
return name;
}
int getPriority()
{
return priority;
}
};
int main()
{
//Queue of patients
PriorityQueue<Patient> patientQueue;
patientQueue.enqueue(Patient("John",2));
patientQueue.enqueue(Patient("Jim",1));
patientQueue.enqueue(Patient("Tim",5));
patientQueue.enqueue(Patient("Cindy",7));
while (patientQueue.getsize() > 0)
{
Patient element = patientQueue.dequeue();
cout << element.getName() << "(priority: " << element.getPriority() << ")"<< endl;
}
return 0;
}