|
|
|
@ -72,6 +72,61 @@ int main() {
|
|
|
|
|
cout << "\nPostorder traversal\n";
|
|
|
|
|
doubleTree.postOrderTraversal();
|
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//EXTRA TESTS CAUSE WHY NOT
|
|
|
|
|
Tree<int> noDupsInt;
|
|
|
|
|
noDupsInt.disableDuplicates();
|
|
|
|
|
Tree<int> yesDupsInt;
|
|
|
|
|
//lets insert some random value
|
|
|
|
|
noDupsInt.insertNode(42);
|
|
|
|
|
yesDupsInt.insertNode(42);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 100; ++i) {
|
|
|
|
|
try {
|
|
|
|
|
yesDupsInt.insertNode(i);
|
|
|
|
|
noDupsInt.insertNode(i); // <- Will thrown an exception when you try to insert a duplicate
|
|
|
|
|
}
|
|
|
|
|
catch ( const exception &e) {
|
|
|
|
|
cout << "Unable to insert " << i << " into noDupsInt tree: " << e.what() << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cout << "Trees: " << endl;
|
|
|
|
|
cout << "No duplicates int tree: " << endl;\
|
|
|
|
|
noDupsInt.printTree();
|
|
|
|
|
getchar();
|
|
|
|
|
|
|
|
|
|
cout << "Duplicates string tree: " << endl;
|
|
|
|
|
yesDupsInt.printTree();
|
|
|
|
|
getchar();
|
|
|
|
|
|
|
|
|
|
Tree<string> noDupsString;
|
|
|
|
|
noDupsString.disableDuplicates();
|
|
|
|
|
Tree<string> yesDupsString;
|
|
|
|
|
noDupsString.insertNode("hjdfj1");
|
|
|
|
|
noDupsString.insertNode("test2");
|
|
|
|
|
noDupsString.insertNode("ztest332");
|
|
|
|
|
noDupsString.insertNode("agasfasfb");
|
|
|
|
|
yesDupsString.insertNode("test1");
|
|
|
|
|
yesDupsString.insertNode("test2");
|
|
|
|
|
yesDupsString.insertNode("test3");
|
|
|
|
|
yesDupsString.insertNode("test4");
|
|
|
|
|
yesDupsString.insertNode("test4");
|
|
|
|
|
try {
|
|
|
|
|
noDupsString.insertNode("test2");
|
|
|
|
|
}
|
|
|
|
|
catch ( const exception &e) {
|
|
|
|
|
cout << "Unable to insert into noDupsString tree: " << e.what() << endl;
|
|
|
|
|
}
|
|
|
|
|
cout << "No duplicates string tree: " << endl;
|
|
|
|
|
noDupsString.printTree();
|
|
|
|
|
getchar();
|
|
|
|
|
cout << "Duplicates string tree: " << endl;
|
|
|
|
|
yesDupsString.printTree();
|
|
|
|
|
|
|
|
|
|
cout << "DONE!" << endl;
|
|
|
|
|
getchar();
|
|
|
|
|
getchar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|