Question

In a AVL tree class, pls use the given information below to complete the function "private AVLNode CopyNode(AVLNode sourcend)" 8 class AVLNode 10 public comparable data; 11 public de left 12 public de righ 13 public int height; 14 15 default constructor 16e public AVLNode (Comparable value) 17 data value 18 left null 19 20 righ null 21 height 0; 22 23 24 parameterized constructor 25 public AVLNode (Comparable value de left1. AVLNode right 1) 26 data value 27 left left1. 28 29 right right1 30 heigh 0; 31 32 The ResetHeight method recomputes height if the 33 34 left or right subtrees have changed 35 void Reset Height) 36 37 int lefth eight -1; int rightheight -1; 38 39 if (left null) leftheight left. heigh 41 if (right null) rightheight righ height 42 43 heigh 1 ath. max (left height rightheight) 45 46 47 public class Tree 48 member attributes 49 private AVLNode root 50 private int size

0 0
Add a comment Improve this question Transcribed image text
Answer #1


    private AVLNode CopyNode(AVLNode sourcend) {
        AVLNode left = null;
        AVLNode right = null;
        if (sourcend.left != null) {
            left = copy(sourcend.left);//copying left subtree
        }
        if (sourcend.right != null) {
            right = copy(sourcend.right);//copying right subtree
        }
        //creating new node...
        return new AVLNode(sourcend.data, left, right);
    }

Add a comment
Know the answer?
Add Answer to:
In a AVL tree class, pls use the given information below to complete the function "private...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++. Test if a Tree is Balanced Use the given Tree class and implement a function...

    C++. Test if a Tree is Balanced Use the given Tree class and implement a function to test if the binary tree is balanced or not. An empty tree is height-balanced. A non-empty binary tree T is balanced if: 1) Left subtree of T is balanced 2) Right subtree of T is balanced 3) The difference between heights of left subtree and right subtree is not more than 1. #include <iostream> using namespace std; template<class ItemType> class Tree { private:...

  • C++. Test if a Tree is Balanced Use the given Tree class and implement a function...

    C++. Test if a Tree is Balanced Use the given Tree class and implement a function to test if the binary tree is balanced or not. An empty tree is height-balanced. A non-empty binary tree T is balanced if: 1) Left subtree of T is balanced 2) Right subtree of T is balanced 3) The difference between heights of left subtree and right subtree is not more than 1. Please MAKE SURE TO CLEARLY SHOW THE CODING. AND YOUR OUTPUT....

  • Implement a method to build an AVL tree out of a sorted (ascending order) array of...

    Implement a method to build an AVL tree out of a sorted (ascending order) array of unique integers, with the fastest possible big O running time. You may implement private helper methods as necessary. If your code builds a tree that is other than an AVL tree, you will not get any credit. If your code builds an AVL tree, but is not the fastest big O implementation, you will get at most 12 points. You may use any of...

  • Java please Given the following numbers in the given order, show the AVL tree. Show the...

    Java please Given the following numbers in the given order, show the AVL tree. Show the steps as you do any rotations.             100, 200, 150, 170, 165, 180, 220, 163, 164 Write the AVL tree code and insert the above numbers. Show the screen shot of the pre-order traversal of the resulting tree. Compare the result with the Red-black tree result I have the code for the RBT, please compare the results from these two trees import java.util.Scanner; /*...

  • Implement an AVL tree stored in a random access file Each node contains an integer key,...

    Implement an AVL tree stored in a random access file Each node contains an integer key, one or more fixed length character strings, a left child reference, a right child reference and a height The format of the file is shown on the next slide The methods you must implement are shown on the followingslides. Duplicate keys cannot be entered in the tree Your implementation MUST NOT load the whole tree in memory. Each operation only makes copies of the...

  • Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree...

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Use following Node class, no height is stored in the Node /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; }...

  • Have to write the tree into a text file? JAVA CODE Binary search tree This is...

    Have to write the tree into a text file? JAVA CODE Binary search tree This is the tree public class Buildbst { private int data; private Buildbst left; private Buildbst right; //Set the binary search tree public Buildbst(int data) { this.data = data; this.left = null; this.right =null; } public int getData() { return data; } public void setData(int data) { this.data = data; } public Buildbst getLeft() { return left; } public void setLeft(Buildbst left) { this.left = left;...

  • 1. Write a function in Tree class which returns true if and only if the tree...

    1. Write a function in Tree class which returns true if and only if the tree satisfies the binary search tree property. The function’s header line is public boolean isValidBST() And in the attached code, you just need to finish the function after the comment: “//Instructor hint: please write your code here:” Make sure you execute your code, and the result in the main function after calling your function should be same as the prompt message I write. Clearly you...

  • I need to do a tree sort method but the treesortMethod is not working /****Binarytree class****\...

    I need to do a tree sort method but the treesortMethod is not working /****Binarytree class****\ package Tree; public class BinaryTree { private TreeNode root; // head of the list    //constructor - create an empty binary tree public BinaryTree() { root = null;    }    //isEmpty() - return true if tree is empty, false otherwise public boolean isEmpty() { return (root == null); }    //deleteTree() - remove all items from tree public void deleteList() { root =...

  • Removing Nodes from a Binary Tree in Java This section requires you to complete the following...

    Removing Nodes from a Binary Tree in Java This section requires you to complete the following method within BinaryTree.java: public void remove(K key) { } The remove method should remove the key from the binary tree and modify the tree accordingly to maintain the Binary Search Tree Principle. If the key does not exist in the binary tree, no nodes should be removed. In case there is a non-null left child, it should take the place of the removed node....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT