Example #1
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);
        }