* A binary tree is a ordered value tree with only two childs per node
*/
public class ArbreBinaire {
-
- private class IntNode {
- private int data;
- private IntNode leftIntNode;
- private IntNode rightIntNode;
-
- IntNode(int value) {
- setData(value);
- setLeftNode(null);
- setRightNode(null);
- }
-
- IntNode(int value, IntNode leftNode, IntNode rightNode) {
- setData(value);
- setLeftNode(leftNode);
- setRightNode(rightNode);
- }
-
- private int getData() {
- return data;
- }
-
- private void setData(int value) {
- data = value;
- }
-
- private IntNode getLeftNode() {
- return leftIntNode;
- }
-
- private void setLeftNode(IntNode leftNode) {
- leftIntNode = leftNode;
- }
-
- private IntNode getRightNode() {
- return rightIntNode;
- }
-
- private void setRightNode(IntNode rightNode) {
- rightIntNode = rightNode;
- }
-
- }
-
- private IntNode rootNode;
+ private Node<Integer> rootNode;
ArbreBinaire() {
setRootNode(null);
}
- private void setRootNode(IntNode node) {
+ private void setRootNode(Node<Integer> node) {
rootNode = node;
}
- private IntNode getRootNode() {
+ private Node<Integer> getRootNode() {
return rootNode;
}
return (getRootNode() == null);
}
- private IntNode inserer_rec(IntNode currentNode, int value) {
+ private Node<Integer> inserer_rec(Node<Integer> currentNode, int value) {
if (currentNode == null) {
- return new IntNode(value);
+ return new Node<Integer>(value);
}
if (value < currentNode.getData()) {
currentNode.setLeftNode(inserer_rec(currentNode.getLeftNode(), value));
setRootNode(inserer_rec(rootNode, value));
}
- private IntNode supprimer_rec(IntNode currentNode, int value) {
+ private Node<Integer> supprimer_rec(Node<Integer> currentNode, int value) {
if (currentNode == null) {
return null;
}
supprimer_rec(rootNode, value);
}
- private boolean hasDataRec(IntNode currentNode, int value) {
+ private boolean hasDataRec(Node<Integer> currentNode, int value) {
if (currentNode == null) {
return false;
}
return hasDataRec(rootNode, value);
}
- private int findSmallestData(IntNode node) {
+ private int findSmallestData(Node<Integer> node) {
return node.getLeftNode() == null ? node.getData() : findSmallestData(node.getLeftNode());
}
- private void afficher_rec(IntNode currentNode) {
+ private void afficher_rec(Node<Integer> currentNode) {
if (currentNode != null) {
afficher_rec(currentNode.getLeftNode());
System.out.print(currentNode.getData() + " ");
System.out.println();
}
- private void afficher_arbre_rec(IntNode currentNode, int column) {
+ private void afficher_arbre_rec(Node<Integer> currentNode, int column) {
if (currentNode != null) {
afficher_arbre_rec(currentNode.getRightNode(), column + 1);
for (int i = 0; i < column; i++) {