-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBST.cpp
More file actions
51 lines (44 loc) · 1 KB
/
BST.cpp
File metadata and controls
51 lines (44 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <algorithm>
#define endl '\n'
#define null NULL
using namespace std;
//rebase
//wakakaka
struct node {
int key;
struct node *left,*right;
};
struct node *newNode(int key){
struct node *temp = (struct node*)malloc(sizeof(struct node));
temp->left = null;
temp->right = null;
temp->key = key;
return temp;
}
struct node *insert(struct node *node,int key){
if (node == null) return newNode(key);
if (key > node->key) node->right = insert(node->right,key);
else if (key < node->key) node->left = insert(node->left,key);
return node;
}
void printInorder(struct node*node){
if (node != null){
printInorder(node->left);
cout << node->key << endl;
printInorder(node->right);
}
}
int main(){
struct node *root = null;
root = insert(root,50);
insert(root,20);
insert(root,10);
insert(root,30);
printInorder(root);
}