BST operatios

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> using namespace std; struct node { int data; struct node *left; struct node *right; }; class BinarySearchTree { public: struct node *root; BinarySearchTree() { root = NULL; } void insert(struct node *root,int value) { if(root == NULL) { root = new struct node; root->data = value; root->left = NULL; root->right = NULL; } else if(root->data>value) { insert(root->left,value); } else { insert(root->right,value); } } void display(struct node *root) { if(root == NULL) return; display(root->left); cout<<root->data<<"\t"; display(root->right); } }; int main() { BinarySearchTree BST; BST.insert(BST.root,5); BST.insert(BST.root,6); BST.display(BST.root); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines