Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void add(int parentkey,boolean isLeft,int key,Object value){
- if(root == null){
- root = new TreeNode(key, value, null);
- System.out.println("Корень " + root.key + "/" + root.value);
- }else{
- TreeNode current;
- current = root;
- while (true)
- {
- if (parentkey == current.key){
- if (isLeft == true){
- current.left = new TreeNode(key, value, current);
- System.out.println("Корень " + current.key + ". Левый элемент " + current.left.key);
- } else {
- current.right = new TreeNode(key, value, current);
- System.out.println("Корень " + current.key + ". Правый элемент " + current.right.key);
- }
- break;
- } else {
- current = current.left;
- if ((parentkey != current.key)&&(current.left == null)){
- current = root;
- current = current.right;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement