-
Notifications
You must be signed in to change notification settings - Fork 0
/
10-heaps.cc
103 lines (97 loc) · 2.64 KB
/
10-heaps.cc
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
99
100
101
102
103
#include <iostream>
#include <limits>
using std::cin;
using std::cout;
using std::endl;
using std::numeric_limits;
#include "idebug.h"
#include "heaps.h"
int main() {
int part;
cin >> part;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
while(part != -1) {
cout << "Part: " << part << "----------------------------------------";
cout << "--------------------------------" << endl;
switch(part) {
/* ---- 01 ------------------------------------------------------------ */
case 1: {
cout << "EPI: ";
cout << "Merge multiple sources Flag" << endl;
vector<vector<int>> m;
readMatrix(m);
HeapMerge<int> h;
vector<int> v = h.merge(m);
printContainer(v);
break;
}
/* ---- 02 ------------------------------------------------------------ */
case 2: {
cout << "EPI: ";
cout << "K-Ineasing-Decreasing Sort" << endl;
vector<int> v;
readArray(v);
printContainer(v);
HeapMerge<int> h;
vector<int> sorted = h.sortKIncreaseDecrease(v);
printContainer(sorted);
break;
}
/* ---- 03 ------------------------------------------------------------ */
case 3: {
cout << "EPI: ";
cout << "Stach using heap" << endl;
vector<int> v;
readArray(v);
printContainer(v);
HStack<int> hs;
for(int i = 0; i < (int) v.size(); i++) {
hs.push(v[i]);
}
for(int i = 0; i < (int) v.size(); i++) {
cout << hs.pop() << " ";
}
cout << endl;
break;
}
/* ---- 04 ------------------------------------------------------------ */
case 4: {
/*
* @TODO Understand this !
*/
break;
}
/* ---- 05 ------------------------------------------------------------ */
case 5: {
/*
* @TODO Understand this !
*/
break;
}
/* ---- 06 ------------------------------------------------------------ */
case 6: {
/*
* @TODO Understand this !
*/
break;
}
/* ---- 08 ------------------------------------------------------------ */
case 8: {
cout << "EPI: ";
cout << "Heap running medium" << endl;
vector<int> v;
readArray(v);
HeapRunningMedian<int> hrm;
for(int i = 0; i < (int) v.size(); i++) {
double median = hrm.add(v[i]);
cout << "Add " << v[i] << ". Current median=" << median << endl;
}
break;
}
default: {
break;
}
}
cin >> part;
}
}