Java实现树的遍历以及打印(递归,非递归)
1 import java.util.LinkedList; 2 import java.util.Stack; 3 4 public class BinarySearchTree1<E extends Comparable <? super E>> { 5 6 private static class BinaryNode<E> { 7 8 E element; 9 BinaryNode<E> left; 10 BinaryNode<E> right; 11 12 BinaryNode(E theElement) { 13 this (theElement, null , null ); 14 } 15 16 BinaryNode(E theElement, BinaryNode<E> lt, BinaryNode<E> rt) { 17 element = theElement; 18 left = lt; 19 right = rt; 20 } 21 22 } 23 24 private BinaryNode<E> root; 25 public void insert(E x){ 26 root = insert(x,root); 27 } 28 29 private BinaryNode<E> insert(E x, BinaryNode<E> t){ 30 31 if