Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- #include <queue>
- #include <cstdlib>
- using namespace std;
- struct BSTNode {
- int value;
- BSTNode* left;
- BSTNode* right;
- };
- void unbalancedInsert(BSTNode* &head, int v)
- {
- //empty tree or foundlocation
- if(head == NULL)
- {
- head = new BSTNode;
- head->value = v;
- head->left = NULL;
- head->right = NULL;
- }
- else if(v < head->value)
- {
- unbalancedInsert(head->left, v);
- }
- else if(v > head->value)
- {
- unbalancedInsert(head->right, v);
- }
- else
- {
- cout << "Duplicate ignored" << endl;
- }
- }
- void inOrder(BSTNode* root)
- {
- }
- void postOrder(BSTNode* root)
- {
- }
- void preOrder(BSTNode* root)
- {
- }
- void levelOrder(BSTNode* root)
- {
- }
- int main() {
- //create the tree
- BSTNode* head = NULL;
- unbalancedInsert(head, 54);
- unbalancedInsert(head, 22);
- unbalancedInsert(head, 17);
- unbalancedInsert(head, 41);
- unbalancedInsert(head, 36);
- unbalancedInsert(head, 30);
- unbalancedInsert(head, 74);
- unbalancedInsert(head, 76);
- unbalancedInsert(head, 26);
- unbalancedInsert(head, 27);
- unbalancedInsert(head, 45);
- unbalancedInsert(head, 82);
- cout << endl;
- cout << "Ricky to the rescue:" << endl;
- cout << "printing inorder: ";
- inOrder(head);
- cout << endl;
- cout<< "Answer: 17 22 26 27 30 36 41 45 54 74 76 82";
- cout << endl;
- cout << endl;
- cout << "printing postorder: ";
- postOrder(head);
- cout << endl;
- cout <<"Answer: 17 27 26 30 36 45 41 22 82 76 74 54 ";
- cout << endl;
- cout << endl;
- cout << endl;
- cout << "Stacey saves the day" << endl;
- cout << "printing preorder: ";
- preOrder(head);
- cout << endl;
- cout <<"Answer: 54 22 17 41 36 30 26 27 45 74 76 82";
- cout << endl;
- cout << endl;
- cout << "Quiet down, Quinn's in Town" << endl;
- cout << "printing levelorder: ";
- levelOrder(head);
- cout << endl;
- cout <<"Answer: 54 22 74 17 41 76 36 45 82 30 26 27";
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment