示例#1
0
        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;
        }
示例#2
0
        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;
        }
示例#3
0
 public LinkedListToBT(llnode head)
 {
     this.head = head;
 }
示例#4
0
 public llnode(int data, llnode next)
 {
     this.data = data;
     this.next = next;
 }