#include #include "class_tree.h" struct Word { string w; int c; }; string to_string(Word wd){ return "(" + wd.w + ", " + to_string(wd.c) + ")"; } bool operator==(Word l, Word r){ return l.w == r.w; } bool operator<(Word l, Word r){ return l.w < r.w; } bool operator>(Word l, Word r){ return l.w > r.w; } // You don't need this next bit to use the tree! struct Word a = {"apple", 27}; struct Word b = {"bear", 2}; void fun(){ if(a > b){ a.c ++; } } ostream& operator<<(ostream& out, Word wd){ return out << "(" << wd.w << ", " << wd.c << ")"; } int main(int argc, char ** argv){ if(argc < 2){ cout << "Usage: " << argv[0] << " filename\n"; return 1; } Tree all_words; ifstream file_stream; file_stream.open(argv[1]); string current_word; while(!file_stream.eof()){ current_word = ""; file_stream >> current_word; if(current_word == "") continue; Word new_word; new_word.w = current_word; new_word.c = 1; Word *find_place; if(all_words.find_reference(new_word, &find_place)) find_place->c++; else all_words.insert(new_word); // Fetch would work like this instead: // Word& our_data = all_words.fetch({"WordWeWant", 0}); // our_data.c += 1; } all_words.print_inorder(); all_words.make_image("word_tree"); return 0; }