Esempio n. 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;
        }
Esempio n. 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;
        }
Esempio n. 3
0
 public LinkedListToBT(llnode head)
 {
     this.head = head;
 }
Esempio n. 4
0
 public llnode(int data, llnode next)
 {
     this.data = data;
     this.next = next;
 }