Пример #1
0
        static void Main(string[] args)
        {
            Hanoi(10, "A", "C", "B");

            Console.WriteLine();
            Console.WriteLine("5! = {0}", FactorialRec(5));

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            ///////////////////////
            LinkedList2 <int> myList = new LinkedList2 <int>();

            myList.AddFirst(1);
            myList.AddFirst(2);
            myList.AddFirst(3);

            Console.WriteLine(myList);
            //Stack<int> mystack3 = new Stack<int>();  ///doesn't work properly yet!!!!
            //while (mystack3.Peek() != null)
            //{
            //    Console.WriteLine(mystack3.Pop());
            //}

            Stack <string> mystack = new Stack <string>();

            mystack.Push("Saint");
            mystack.Push("Martin");
            mystack.Push("2020");
            mystack.Pop();
            //Console.WriteLine(mystack.Pop());
            //Console.WriteLine(mystack.Pop());
            //Console.WriteLine(mystack.Pop());

            Console.WriteLine(mystack);


            //application for queues: reverse the contents of a file
            StreamReader   inFile   = new StreamReader("input.txt");
            Stack <string> myStack2 = new Stack <string>();

            //read every line from the file
            string line = inFile.ReadLine();

            while (line != null)
            {
                myStack2.Push(line);
                line = inFile.ReadLine();
            }
            Console.WriteLine(myStack2);
            inFile.Close();

            StreamWriter outFile = new StreamWriter("ouput.txt");

            while (myStack2.Peek() != null)
            {
                outFile.WriteLine(myStack2.Pop());
            }
            outFile.Close();



            Queue myQueue = new Queue();

            myQueue.Enqueue(10);
            myQueue.Enqueue(20);
            myQueue.Enqueue(30);
            myQueue.Enqueue(40);
            Console.WriteLine(myQueue.Dequeue());
            Console.WriteLine(myQueue.Dequeue());
            Console.WriteLine(myQueue.Dequeue());
            Console.WriteLine(myQueue.Dequeue());


            Stack <int> myStack4 = new Stack <int>();

            myStack4.Push(10);
            myStack4.Push(20);
            myStack4.Push(30);
            myStack4.Push(40);
            Console.WriteLine(myStack4.Pop());
            Console.WriteLine(myStack4.Pop());
            Console.WriteLine(myStack4.Pop());
            Console.WriteLine(myStack4.Pop());

            BinarySearchTree myTree = new BinarySearchTree();

            myTree.Insert(10);
            myTree.Insert(5);
            myTree.Insert(3);
            myTree.Insert(15);
            myTree.Insert(12);
            myTree.Insert(20);
            myTree.Insert(30);
            myTree.Insert(13);

            Console.WriteLine(myTree.GetMaxValue());

            myTree.PrintPreOrder();
            myTree.PrintInOrder();
            myTree.DisplayHeight();
            myTree.DisplayNumLeaves();
        }
Пример #2
0
        static void Main(string[] args)
        {
            LinkedList2 <int> myList = new LinkedList2 <int>();

            myList.AddFirst(1);
            myList.AddFirst(2);
            myList.AddFirst(3);

            Console.WriteLine(myList);
            //Stack<int> mystack3 = new Stack<int>();  ///doesn't work properly yet!!!!
            //Doesn't work with integers
            //while (mystack3.Peek() != null)
            //{
            //    Console.WriteLine(mystack3.Pop());
            //}

            //stacking string values to mystack
            Stack <string> mystack = new Stack <string>();

            mystack.Push("Saint");
            mystack.Push("Martin");
            mystack.Push("2020");
            mystack.Pop();
            //Console.WriteLine(mystack.Pop());
            //Console.WriteLine(mystack.Pop());
            //Console.WriteLine(mystack.Pop());

            Console.WriteLine(mystack);


            //application for queues: reverse the contents of a file
            StreamReader   inFile   = new StreamReader("input.txt");
            Stack <string> myStack2 = new Stack <string>();

            //read every line from the file
            string line = inFile.ReadLine();

            while (line != null)
            {
                myStack2.Push(line);
                line = inFile.ReadLine();
            }
            Console.WriteLine(myStack2);
            inFile.Close();

            StreamWriter outFile = new StreamWriter("ouput.txt");

            while (myStack2.Peek() != null)
            {
                outFile.WriteLine(myStack2.Pop());
            }
            outFile.Close();



            Queue myQueue = new Queue();

            myQueue.Enqueue(10);
            myQueue.Enqueue(20);
            myQueue.Enqueue(30);
            myQueue.Enqueue(40);
            Console.WriteLine(myQueue.Dequeue());
            Console.WriteLine(myQueue.Dequeue());
            Console.WriteLine(myQueue.Dequeue());
            Console.WriteLine(myQueue.Dequeue());


            Stack <int> myStack4 = new Stack <int>();

            myStack4.Push(10);
            myStack4.Push(20);
            myStack4.Push(30);
            myStack4.Push(40);
            Console.WriteLine(myStack4.Pop());
            Console.WriteLine(myStack4.Pop());
            Console.WriteLine(myStack4.Pop());
            Console.WriteLine(myStack4.Pop());

            BinarySearchTree myTree = new BinarySearchTree();

            myTree.Insert(21);
            myTree.Insert(3);
            myTree.Insert(-3);
            myTree.Insert(9);
            myTree.Insert(3);

            Console.WriteLine(myTree.GetMaxValue());
        }