Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Binary Tree
//Title of this code #include <iostream> using namespace std; struct node { node* parent; node* left; node* right; int val; int balance; bool color; // for traversal node(int val, node* parent) { this->parent = parent; this->val = val; this->left = NULL; this->right = NULL; this->balance = 0; this->color = 0; } }; class AVLTree { private: node* root; bool color; public: AVLTree() { root = NULL; color = 0; } ~AVLTree() { } void insertVal(int val) { node* n = root; if (root == NULL) { root = new node(val, NULL); return; } while (true) { if (n->val > val) { if (n->left != NULL) n = n->left; else { n->left = new node(val, n); break; } } else { if (n->right != NULL) n = n->right; else { n->right = new node(val, n); break; } } } } void deleteVal(int val) { } void printTree() { bool visitedColor = !color; node* n = root; while(n != NULL) { if (n->left != NULL && n->left->color != visitedColor) { n = n->left; } else if (n->right != NULL && n->right->color != visitedColor) { n = n->right; } else { n->color = visitedColor; cout << n->val; if (n->left != NULL) cout << " left child: " << n->left->val; if (n->right != NULL) cout << " right child: " << n->right->val; cout << endl; n = n->parent; } } color = visitedColor; } }; int main() { AVLTree t; t.insertVal(4); t.insertVal(1); t.insertVal(6); t.insertVal(5); t.printTree(); cout << "Hello, world!\n"; }
run
|
edit
|
history
|
help
0
Vector
cotton farm 0.0.1.0
precision and fixed point notation
pow implementation
decode
remove dublicates from string using recursion
Count of factors
dodawanie "MIECIERZY"
Reverse factorial
inorder traversal