Red de conocimiento informático - Descarga de software - ¿Cómo construir un árbol binario usando Java?

¿Cómo construir un árbol binario usando Java?

Defina una clase de nodo:\x0d\public class Node {\x0d\ private int value;\x0d\ private Node leftNode;\x0d\ private Node rightNode;\x0d\ \x0d\ public Node getRightNode ( ) {\x0d\ return rightNode;\x0d\ }\x0d\ public void setRightNode(Nodo rightNode) {\x0d\ this.rightNode = rightNode;\x0d\ }\x0d\ public int getValue() {\x0d\ valor de retorno ;\x0d\ }\x0d\ public void setValue(int valor) {\x0d\ this.value = valor;\x0d\ }\x0d\ public Node getLeftNode() {\x0d\ return leftNode;\x0d\ }\ x0d \ public void setLeftNode(Node leftNode) {\x0d\ this.leftNode = leftNode;\x0d\ }\x0d\ \x0d\}\x0d\ \x0d\Inicializa el árbol de nodos: \x0d\public void initNodeTree()\ x0d \ {\x0d\ int nodeNumber;\x0d\ HashMap map = new HashMap();\x0d\ Node nodeTree = new Node();\x0d\ \x0d\ Lector de escáner = new Scanner(System.in);\x0d \ \x0d\ nodeNumber = lector.nextInt();\x0d\ for(int i = 0; i map, int nodeValue, Node parentNode) {\x0d\ int value = 0;\x0d\ if (map.containsKey(" L " + nodeValue)) {\x0d\ value = map.get("L" + nodeValue);\x0d\ Node leftNode = new Node();\x0d\ leftNode.setValue(value);\x0d\ parentNode.setLeftNode ( leftNode);\x0d\ \x0d\ setChildNode(map, value, leftNode);\x0d\ } \x0d\ \x0d\ if (map.containsKey("R" + nodeValue)) {\x0d\ value = map. ("R" + nodeValue);\x0d\ Node rightNode = new Node();\x0d\ rightNode.setValue(valor);\x0d\ parentNode.setRightNode(rightNode);\x0d\ \x0d\ setChildNode(mapa, valor , rightNode);\x0d\ }\x0d\ }\x0d\ \x0d\Preorder atraviesa el árbol de nodos:\x0d\public void preTraversal(Node

nodeTree) {\x0d\ if (nodeTree != null) {\x0d\ System.out.print(nodeTree.getValue() + "\t");\x0d\ preTraversal(nodeTree.getLeftNode());\x0d\ preTraversal(nodeTree.getRightNode());\x0d\ }\x0d\ }