You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.8 KiB

#include <iostream>
#include <string>
#include <fstream>
#include <chrono>
#include "RBTree.h"
#include "tree.h"
using namespace std;
int main() {
ifstream input;
input.open("B_Tree_Input.txt");
string strValue;
int intValue;
RBTree rbtree;
auto start = chrono::steady_clock::now();
while (!input.eof()) {
getline(input, strValue);
intValue = stoi(strValue);
rbtree.insertValue(intValue);
}
auto end = chrono::steady_clock::now();
cout << "Black-Red Tree insertion time: "
<< chrono::duration_cast<chrono::nanoseconds>(end - start).count()
<< " nanoseconds" << endl;
input.clear();
input.seekg(0, ios::beg);
tree tree234;
start = chrono::steady_clock::now();
while (!input.eof()) {
getline(input, strValue);
intValue = stoi(strValue);
tree234.insert(intValue);
}
end = chrono::steady_clock::now();
cout << "2-3-4 Tree insertion time: "
<< chrono::duration_cast<chrono::nanoseconds>(end - start).count()
<< " nanoseconds" << endl;
cout << endl;
ifstream searches;
searches.open("B_Tree_Searches.txt");
string strSearch;
start = chrono::steady_clock::now();
while (!searches.eof()) {
getline(searches, strSearch);
bool found = rbtree.searchStart(stoi(strSearch));
}
end = chrono::steady_clock::now();
cout << "Black-Red Tree search time: "
<< chrono::duration_cast<chrono::nanoseconds>(end - start).count()
<< " nanoseconds" << endl;
searches.clear();
searches.seekg(0, ios::beg);
start = chrono::steady_clock::now();
while (!searches.eof()) {
getline(searches, strSearch);
bool found = tree234.searchBool(stoi(strSearch));
}
end = chrono::steady_clock::now();
cout << "2-3-4 Tree search time: "
<< chrono::duration_cast<chrono::nanoseconds>(end - start).count()
<< " nanoseconds" << endl;
}