Advertisement
UriSteiff

עץ מאוזן

May 26th, 2021
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. public static void sortedArrayToBST(AVLTree t, int arr[], int start, int end) {
  2.      
  3.          /* Base Case */
  4.          if (start > end) {
  5.              return;
  6.          }
  7.    
  8.          /* Get the middle element and make it root */
  9.          int mid = (start + end) / 2;
  10.          t.insert(arr[mid], false);
  11.    
  12.          /* Recursively construct the left subtree and make it
  13.           left child of root */
  14.          sortedArrayToBST(t, arr, start, mid - 1);
  15.    
  16.          /* Recursively construct the right subtree and make it
  17.           right child of root */
  18.          sortedArrayToBST(t, arr, mid + 1, end);
  19.            
  20.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement