- #1
transgalactic
- 1,395
- 0
ok my gole is to build a software that
takes a numbers and splits it like this into nodes of a tree
i have tried some code but it doesn't give me the right resolt
i tried to implement it in this code
takes a numbers and splits it like this into nodes of a tree
Code:
48
8 6
2 4 2 3
1 2 2 1 2 1 3
1 2
i have tried some code but it doesn't give me the right resolt
i tried to implement it in this code
Code:
public class main {
public static void main(String[] args) {
BTree t=new BTree();
t.insert(16);
}
}
public class BTree {
BNode root;
BTree()
{
root=null;
}
public void insert(int num){
root=new BNode(num);
root.insert(num);
}
}
public class BNode {
private BNode left;
private BNode right;
private int data;
BNode(){
left=null;
right=null;
}
BNode(int num){
this.data=num;
}
public void insert(int num){
int sm=small(num);
int large=num/sm;
this.data=num;
if (num>large){
this.right=new BNode(sm);
this.left=new BNode (large);
left.insert(large);
}
}
public static int small(int num){
double sqr=Math.sqrt(num);
int small=(int)Math.floor(sqr);
while (num%small!=0){
small--;
}
return small;
}
}