public Node<int> LLtoBT(LinkedList<int> list) { if (list == null) return null; Node<int> node = new Node<int>(list.First.Value); Node<int> root = node; Queue<Node<int>> queue = new Queue<Node<int>>(); queue.Enqueue(node); LinkedListNode<int> head = list.First; head = head.Next; while (head != null) { node = queue.Dequeue(); Node<int> left = null; Node<int> right = null; left = new Node<int>(head.Value); head = head.Next; queue.Enqueue(left); if (head != null) { right = new Node<int>(head.Value); head = head.Next; queue.Enqueue(right); } node.left = left; node.right = right; } return root; }
public llnode CreateList(int size) { llnode cur = null; for (int i = 0; i < size; i++) { cur = new llnode(i); cur.next = head; head = cur; } return head; }
public LinkedListToBT(llnode head) { this.head = head; }
public llnode(int data, llnode next) { this.data = data; this.next = next; }