Example #1
0
        static void Main(string[] args)
        {
            Node root = new Node(50);

            root.left        = new Node(25);
            root.right       = new Node(70);
            root.left.left   = new Node(10);
            root.left.right  = new Node(40);
            root.right.left  = new Node(60);
            root.right.right = new Node(80);

            Tree bst    = new Tree();
            MyLL mylist = new MyLL();

            mylist = bst.BSTtoLinkedList(mylist, root);

            mylist.PrintNodes();
        }
Example #2
0
        // Sets nextRight of all nodes of a tree
        public MyLL BSTtoLinkedList(MyLL list, Node root)
        {
            if (root == null)
            {
                return(null);
            }
            Queue <Node> q = new Queue <Node>();

            q.Enqueue(root);
            while (q.Count() > 0)
            {
                root = q.Dequeue();
                list.AddTail(root.data);
                if (root.left != null)
                {
                    q.Enqueue(root.left);
                }
                if (root.right != null)
                {
                    q.Enqueue(root.right);
                }
            }
            return(list);
        }