What is the error in the code that I have written?
import java.util.*;
public class replace_with_the_greatest_sum {
public class Node{
int data;
Node left;
Node right;
}
static Node root;
public static void getInorderArray(int[]arr){
root=construct(arr, 0, arr.length);
//Node nn=root.left;
root=maxsum(root);
while(root.left!=null){
root.left=maxsum(root.left);
root.left=root.left.left;
}
while(root.right!=null){
root.right=maxsum(root.right);
root.right=root.right.right;
}
int []arr1=new int[arr.length];
preorder(root, arr1, 0);
}
private static Node construct(int[]arr, int lo, int hi){
if(lo>hi){
return null;
}
int mid=(lo+hi)/2;
root.data=arr[mid];
root.left=construct(arr, lo, mid-1);
root.right=construct(arr, mid+1, hi);
return root;
}
public static Node maxsum(Node root){
if(root==null){
return null;
}
root.data=root.data+maxsum(root.right).data;
return root;
}
public static void preorder(Node node, int []arr, int i){
if(node==null){
return;
}
System.out.print(node.data+" ");
preorder(node.left, arr, i);
preorder(node.right, arr, i);
return;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int []arr=new int[n];
for(int i=0; i<n; i++){
arr[i]=sc.nextInt();
}
getInorderArray(arr);
}
}