public static void preOrder(TNode node) { if (node == null) return; preOrder(node.left); Console.Write(" " + node.data); preOrder(node.right); }
public static TNode listToT(int[] array, int i, int n) { if (i > n) return null; TNode root = new TNode(array[i + (n - i) / 2]); root.left = listToT(array, i, i + (n - i) / 2-1); root.right = listToT(array, i + (n - i) / 2 + 1,n); return root; }
public static TNode listToTreeRecursiv(ref LNode header, int n) { //Base Case if (n <= 0) return null; TNode left = listToTreeRecursiv(ref header, n/2); TNode root = new TNode(header.data); root.left = left; header = header.next; root.right = listToTreeRecursiv(ref header, n - n / 2 - 1); return root; }