Generation

generate functionThu, 05 Jan 2023

Tree constructor (strArr)

public class Tree { public static Node createTree(String[] nodeVals){ Node root = null; for(String s : nodeVals){ root = insert(root, s); } return root; } public static Node insert(Node root, String s){ if(root == null) return new Node(s); if(s.compareTo(root.data) < 0){ root.left = insert(root.left, s); } else if(s.compareTo(root.data) > 0){ root.right = insert(root.right, s); } return root; } }

Questions about programming?Chat with your personal AI assistant