I can not understand why my recursive call is bad here. Is there anything wrong with me and how can I fix it, put some light on it? I appreciate any and all help.
I have an array that is full of random integers, I am trying to make a completely left-odd binary tree.
main:
public static zero main (string [] args) // // to declare new array integer value int [] array1 = new int [26] ; Randerers (array 1, 1, 50); For (int x = 0; x & lt; array1.length; x ++) System.out.print (array 1 [x] + ""); // Build Squad Tree Bintery Tree 1 = New Binterity (array 1 [0]); For (int x = 1; x & lt; array1.length; x ++) tree 1.addLeft (new binarytree (array 1 [x])); Tree1.print (); } Public static zero randere (int [] list, int short, int up) {random rand = new random (); For (int i = 0; i & lt; list.length; i ++) {list [i] = rand.nextInt (above - less + 1) + less; }}}
addLeft:
Add Public Zero Lift (Binterity Subtree) {if (leftChild! = Null) {addLeft (leftChild); } LeftChild = subtree; }
Most likely your add-left function should look like this: < / P>
Public Zero Add Lift (Binterity Subtree) {if (leftChild! = Null) {leftChild.addLeft (subtree); } LeftChild = subtree; }
Note: this does not really sort anything if you want a sorted left squared binary tree, then the function should look like this (something):
Public Zero Add-Left (Binterity Subtree) {if (subtitle.value; value) {int tmp = value; Value = subtree.value; Subtree.value = tmp; } If (left child! = Null) {leftChild.addLeft (subtitles); } LeftChild = subtree; }
I did this by swapping prices due to the method of applying this tree if it were the right binary tree on the left, you should leave the nodes left and right, Could be sorted from
Comments
Post a Comment