-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchecker.cpp
More file actions
90 lines (54 loc) · 2.17 KB
/
checker.cpp
File metadata and controls
90 lines (54 loc) · 2.17 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
#include <iostream>
#include <vector>
#include <climits>
#include "btree/btree.h"
#include "fibonacci_heap/fibonacci_heap.h"
#include "fibonacci_heap/fibonacci_heap_node.h"
#include "graph/graph_on_adjacency_matrix.h"
int main() {
const std::vector<int> data = { -7, -5, -4, 0, -1, 3, 7, 3, 2, 1, -1, 5, 9, 15, 2, 4, 2, 0, 16, -2 };
std::cout << "///////////////////" << std::endl <<
"/// BTREE CHECK ///" << std::endl <<
"///////////////////" << std::endl << std::endl;
BTree<int, int*> tree(3);
for (const int& w : data) {
tree.add(w, new int(w));
std::cout << "element: " << w <<
" value: " << *tree.lookup(w) <<
" does w+1 element exist: " << tree.contains(w+1) << std::endl;
}
std::cout << std::endl;
// checking elements removing
for (const int& w : data) {
// tree.remove(w);
auto elements = tree.lookupRange(INT_MIN, INT_MAX);
for (const int* value : elements)
std::cout << *value << " ";
std::cout << std::endl;
}
std::cout << std::endl;
std::cout << "////////////////////////////" << std::endl <<
"/// FIBONACCI HEAP CHECK ///" << std::endl <<
"////////////////////////////" << std::endl << std::endl;
FibonacciHeap<int, int> heap(INT_MIN);
int it = 1;
std::vector<Node<int, int>*> nodes;
for (const int& w : data) {
nodes.push_back(new Node(w, w));
heap.insert(nodes.back());
std::cout << "min element after " << it++ << " insertion " << heap.findMin()->value << std::endl;
}
std::cout << std::endl;
for (int i = 0; i < data.size(); i++) {
heap.deleteItem(nodes[i]);
if (i == data.size() - 1)
continue;
Node<int, int>* minNode = heap.findMin();
if (minNode == nullptr) {
std::cout << "heap is empty!" << std::endl;
break;
}
std::cout << "min element after " << i+1 << " deletion " << minNode->value << std::endl;
}
return 0;
}