-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree.java
More file actions
42 lines (39 loc) · 1.09 KB
/
Copy pathTree.java
File metadata and controls
42 lines (39 loc) · 1.09 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
package xyz.squig;
public class Tree {
TreeNode head;
public Tree(){
head = null;
}
public void addTreeNode(int rank, int x, int y, int xa, int ya){
TreeNode newTreeNode = new TreeNode();
newTreeNode.rank = rank;
newTreeNode.x = x;
newTreeNode.y = y;
newTreeNode.xa = xa;
newTreeNode.ya = ya;
if(head == null){
head = newTreeNode;
}
else{
TreeNode current = head;
TreeNode parent;
while(true){
parent = current;
if(rank < current.rank){
current = current.leftTreeNode;
if(current == null){
parent.leftTreeNode = newTreeNode;
break;
}
}
else{
current = current.rightTreeNode;
if(current == null){
parent.rightTreeNode = newTreeNode;
break;
}
}
}
}
}
}