-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinintree.java
More file actions
57 lines (56 loc) · 1.04 KB
/
Copy pathMinintree.java
File metadata and controls
57 lines (56 loc) · 1.04 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
52
53
54
55
56
57
class node
{
int data;
node left,right;
public node(int data)
{
this.data=data;
this.right=null;
this.left=null;
}
}
class BST
{
node root;
public void insert(int data)
{
root=insertrec(root,data);
}
node insertrec(node root,int data)
{
if(root==null)
{
return new node(data);
}
else if(data<root.data)
{
root.left=insertrec(root.left,data);
}
else
{
root.right=insertrec(root.right,data);
}
return root;
}
public int minnode()
{
if (root==null) return -1;
node temp=root;
while(temp.left!=null)
{
temp=temp.left;
}
return temp.data;
}
}
public class Minintree {
public static void main(String args[])
{
BST bst=new BST();
bst.insert(50);
bst.insert(40);
bst.insert(65);
bst.insert(75);
System.out.println(bst.minnode());
}
}