Skip to content

Instantly share code, notes, and snippets.

@orlp
Forked from Geertex/gist:d68b9df0cd59ad3f68c4
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orlp/71b7a2976d82be1b2f6f to your computer and use it in GitHub Desktop.
Save orlp/71b7a2976d82be1b2f6f to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <chrono>
#include <memory>
#include <cstdlib>
#include "splay_tree.h"
#include "avl_tree.h"
int main(int argc, char** argv) {
std::string word;
std::vector<std::string> words;
std::ifstream input("wordlist1.txt");
while (std::getline(input, word)) {
words.push_back(word);
}
SplayTree<std::string> splay_tree;
auto start = std::chrono::high_resolution_clock::now();
for (auto word : words) splay_tree.insert(word);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = end - start;
std::cout << "create splay_tree took" << elapsed.count() << " time" << '\n';
AVLTree<std::string> avl_tree;
start = std::chrono::high_resolution_clock::now();
for (auto word : words) avl_tree.insert(word);
end = std::chrono::high_resolution_clock::now();
elapsed = end - start;
std::cout << "create avl_tree took" << elapsed.count() << " time" << '\n';
//for (int i = 1; i <= 25; i++) {
// int n = rand() % 50;
// tree.remove(tree.search(n));
//}
//tree.remove(tree.search(36));
tree.save_as_dot("test.dot");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment