Java简易二叉树排序

```int[] arr = {17, 12, 19, 10, 15, 18, 25, 8, 11, 13, 16, 22};
```

`package Love;public class Node {    private int data;    private Node left;    private Node right;        public Node() {            }        public Node(int data) {        this.data = data;    }}`

`package Love;public class BinaryTree {    private Node root;        public BinaryTree() {            }}`

`package Love;public class BinaryTree {    private Node root;        public BinaryTree() {            }        public void addNode(int data) {        if (root == null) {            root = new Node(data);        }     }}`

`package Love;public class Node {    private int data;    private Node left;    private Node right;        public Node() {            }        public Node(int data) {        this.data = data;    }        public void add(int data) {        if (this.data > data) {            if (this.left == null) {                this.left = new Node(data);            } else {                this.left.add(data);            }        } else {            if (this.right == null) {                this.right = new Node(data);            } else {                this.right.add(data);            }        }    }}`

`package Love;public class BinaryTree {    private Node root;    public BinaryTree() {    }    public void addNode(int data) {        if (root == null) {            root = new Node(data);        } else {            root.add(data);        }    }}`

`package Love;/** * Hello world! */public class App {    public static void main(String[] args) {        int[] arr = {17, 12, 19, 10, 15, 18, 25, 8, 11, 13, 16, 22};        BinaryTree bt = new BinaryTree();        for (int a : arr) {            bt.addNode(a);        }            }}`

`package Love;public class BinaryTree {    private Node root;    public BinaryTree() {    }    public void addNode(int data) {        if (root == null) {            root = new Node(data);        } else {            root.add(data);        }    }        public void printNode() {        if (root != null) {            root.print();        }    }}`

`package Love;public class Node {    private int data;    private Node left;    private Node right;        public Node() {            }        public Node(int data) {        this.data = data;    }        public void add(int data) {        if (this.data > data) {            if (this.left == null) {                this.left = new Node(data);            } else {                this.left.add(data);            }        } else {            if (this.right == null) {                this.right = new Node(data);            } else {                this.right.add(data);            }        }    }        public void print() {        if (this.left != null) {            this.left.print();        }        System.out.print(this.data + " ");        if (this.right != null) {            this.right.print();        }    }}`

`package Love;/** * Hello world! */public class App {    public static void main(String[] args) {        int[] arr = {17, 12, 19, 10, 15, 18, 25, 8, 11, 13, 16, 22};        BinaryTree bt = new BinaryTree();        for (int a : arr) {            bt.addNode(a);        }                bt.printNode();    }}`

`8 10 11 12 13 15 16 17 18 19 22 25`

`public void preOrderPrint() {    System.out.print(this.data + " ");    if (this.left != null) {        this.left.preOrderPrint();    }    if (this.right != null) {        this.right.preOrderPrint();    }}public void inOrderPrint() {    if (this.left != null) {        this.left.inOrderPrint();    }    System.out.print(this.data + " ");    if (this.right != null) {        this.right.inOrderPrint();    }}public void postOrderPrint() {    if (this.left != null) {        this.left.preOrderPrint();    }    if (this.right != null) {        this.right.preOrderPrint();    }    System.out.print(this.data + " ");}`

`17 12 10 8 11 15 13 16 19 18 25 228 10 11 12 13 15 16 17 18 19 22 2512 10 8 11 15 13 16 19 18 25 22 17 `