-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
56 lines (47 loc) · 1.83 KB
/
main.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
55
56
#include <iostream>
#include "2_3Tree.h"
#include <fstream>
#include <chrono>
using namespace std;
//Example program implementing 2-3 Tree
int main() {
BNode<int> * ex; //Declaring an instance of a node
BTree<int> a; //Declaring the tree that uses ints.
for(int i = 0; i < 10; ++i) a.insert(i); //Inserting some values
a.traverse(); //Traversing the tree on ascending order.
a.remove(5); //Removing an element
cout << "\n";
a.traverseInverse(); //Traversing on descending order
cout << "\n";
ex = a.search(5); //Searching the tree for the element. If it is found, it returns a pointer to the node; if not it returns NULL
if(!ex) cout << "The number is not in the tree\n";
cout << a.heightSearch(9) << "\n"; //Returns an int showing the height of the node. -1 if there is no node with the value
cout << a.depthSearch(9) << "\n"; // Returns an int showing the depth of the node. -1 if there is no node with the value
cout << a.levelSearch(9) << "\n"; // Returns an int showing the level of the node. -1 if there is no node with the value
}
/*
BTree<int> b;
int arr[10];
void trial(int index){
int number = arr[index];
chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
cout << b.search(number);
chrono::high_resolution_clock::time_point t2 = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::microseconds>(t2-t1).count();
cout << "Time for " << number << " is: " << duration << "microseconds" << "\n";
}
int main() {
ifstream myfile;
ifstream otherFile;
int a;
myfile.open("numbers.txt");
for (int i = 0; i < 100000; ++i) {
myfile >> a;
b.insert(a);
}
otherFile.open("searches.txt");
for (int i = 0; i < 10; ++i) {
otherFile >> arr[i];
trial(i);
}
}*/