public static void printList(LNode node) { while (node != null) { System.Console.WriteLine(" "+node.data); node = node.next; } }
public static int countLNode(LNode header) { if (header == null) return 0; int count = 0; LNode temp = header; while (temp != null) { temp = temp.next; count++; } return count; }
public static void pushF(LNode head, int data) { LNode newNode = new LNode(data); newNode.next = head; head = newNode; }
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; }
public static TNode listToTree(LNode header) { int n = LNode.countLNode(header); return listToTreeRecursiv(ref header, n); }