Exemplo n.º 1
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!!!!
            //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(21);
            myTree.Insert(3);
            myTree.Insert(-3);
            myTree.Insert(9);
            myTree.Insert(3);

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