private static void PrintQueue()
        {
            Console.WriteLine("-----------------------------------");
            Console.WriteLine("PRINT ELEMENTS IN QUEUE");
            Console.WriteLine("-----------------------------------");

            var list = new MyQueue <int>();

            list.Push(20);
            list.Push(10);
            list.PrintNodes();

            list.Pop();
            list.PrintNodes();
        }
Exemple #2
0
        private void PrintBreadthFirstTraversal(TreeNode <T> root)
        {
            var queue = new MyQueue <TreeNode <T> >();

            Console.WriteLine(root.key);
            queue.Push(root);

            while (!queue.IsEmpty())
            {
                var node = queue.Pop();

                if (node.Data.Left != null)
                {
                    Console.WriteLine(node.Data.Left.key);
                    queue.Push(node.Data.Left);
                }
                if (node.Data.Right != null)
                {
                    Console.WriteLine(node.Data.Right.key);
                    queue.Push(node.Data.Right);
                }
            }
        }