-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbtree.java
117 lines (95 loc) · 1.64 KB
/
btree.java
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Rosenkrantz
*/
import java.util.*;
public class btree {
int data;
btree left;
btree right;
btree head;
public btree(int d)
{
data=d;
left=null;
right=null;
head=this;
System.out.println(head.data);
}
public btree(int d,int i)
{
data=d;
left=null;
right=null;
}
void add(int d)
{
btree n=this.head;
boolean done=false;
btree newd=new btree(d,1);
while(!done)
{
if(d>n.data)
{
if(n.right==null)
{ n.right=newd;
done=true;
}
else
n=n.right;
}
else
if(d<n.data)
{
if(n.left==null)
{ n.left=newd;
done=true;
}
else
n=n.left;
}
else
if(d==n.data)
{
System.out.println("No duplicates");
done=true;
}
}
}
void removeNode()
{
}
void inorder(btree p)
{
if(p!=null)
{
inorder(p.left);
System.out.println(p.data);
inorder(p.right);
}
}
btree gethead()
{
return head;
}
public void BFS(btree p)
{
LinkedList ll=new LinkedList();
// ll.add(2);
}
public static void main(String args[])
{
btree b=new btree(5);
b.add(2);
b.add(7);
b.add(6);
b.add(3);
b.add(2);
b.add(4);
b.inorder(b.gethead());
}
}