-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbst.cpp
52 lines (42 loc) · 964 Bytes
/
bst.cpp
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
52
#include "bst.h"
#include<string>
#include<iostream>
using namespace std;
BST::BST()
{
root=NULL;
}
BST::~BST(){
}
void BST::add(int value){
addhelper(root,value);
}
void BST :: printsideways(){
string len="";
printhelpersideways(root,""+len);
}
void BST :: printhelpersideways(TreeNode * Node, string len){
if(Node!=NULL){
printhelpersideways(Node->left,len+" ");
cout<<len<<Node->data<<endl;
printhelpersideways(Node->right,len+" ");
}
}
void BST::addhelper(TreeNode * &node , int value){
if(node==NULL){
node=new TreeNode(value);
}else if(node->data<value)
addhelper(node->right,value);
else if(node->data>value)
addhelper(node->left,value);
}
void BST :: getmin(){
getminHelper( root);
}
void BST :: getminHelper(TreeNode * node){
if ((node->left)==NULL){
cout<< node->data;
}
else
getminHelper(node->left);
}