Example #1
0
        static void Main(string[] args)
        {
            var easyStack = new EasyStack <int>();

            easyStack.Push(1);
            easyStack.Push(2);
            easyStack.Push(3);

            var item1 = easyStack.Pop();
            var item2 = easyStack.Peek();

            Console.WriteLine(item1);
            Console.WriteLine(item2);

            Console.ReadLine();

            Stack <double> stack = new Stack <double>();

            var linkedStack = new LinkedStack <int>();

            linkedStack.Push(10);
            linkedStack.Push(20);
            linkedStack.Push(30);
            //linkedStack.Push(20);
            //linkedStack.Push(30);
            //linkedStack.Push(40);
            //linkedStack.Push(50);

            Console.WriteLine(linkedStack.Peek());
            Console.WriteLine(linkedStack.Pop());
            Console.WriteLine(linkedStack.Pop());
            Console.WriteLine(linkedStack.Peek());

            Console.ReadLine();

            var arrayStack = new ArrayStack <int>(5);

            arrayStack.Push(100);
            arrayStack.Push(200);
            arrayStack.Push(300);
            arrayStack.Push(400);
            arrayStack.Push(500);
            //arrayStack.Push(600);

            Console.WriteLine(arrayStack.Count);
            Console.WriteLine(arrayStack.Peek());
            Console.WriteLine(arrayStack.Count);
            Console.WriteLine(arrayStack.MaxCount);
            Console.WriteLine(arrayStack.Pop());
            Console.WriteLine(arrayStack.MaxCount);
            Console.WriteLine(arrayStack.Count);
            Console.WriteLine(arrayStack.Pop());
            Console.WriteLine(arrayStack.MaxCount);
            Console.WriteLine(arrayStack.Count);
            Console.WriteLine(arrayStack.Peek());

            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            var easyStack = new EasyStack <int>();

            easyStack.Push(1);
            easyStack.Push(2);
            easyStack.Push(3);
            easyStack.Push(4);
            easyStack.Push(5);
            Console.WriteLine("кількість елементів до операцій = " + easyStack.Count);
            var item  = easyStack.Pop();
            var item2 = easyStack.Pop();
            var item3 = easyStack.Peek();

            Console.WriteLine("кількість елементів після операцій = " + easyStack.Count);

            Console.WriteLine(item);
            Console.WriteLine(item2);
            Console.WriteLine(item3);
            Console.ReadLine();

            Stack <double> stack = new Stack <double>();

            var linkedStack = new LinkedStack <int>();

            linkedStack.Push(10);
            linkedStack.Push(20);
            linkedStack.Push(30);


            Console.WriteLine(linkedStack.Peek());
            Console.WriteLine(linkedStack.Pop());
            Console.WriteLine(linkedStack.Pop());
            Console.WriteLine(linkedStack.Peek());
            Console.ReadLine();


            var arrayStack = new ArrayStack <int>(5);

            Console.WriteLine(arrayStack.Count);
            arrayStack.Push(100);
            Console.WriteLine(arrayStack.Count);
            arrayStack.Push(200);
            arrayStack.Push(300);
            arrayStack.Push(400);
            arrayStack.Push(500);

            Console.WriteLine(arrayStack.Peek());
            Console.WriteLine(arrayStack.Pop());
            Console.WriteLine(arrayStack.Pop());
            Console.WriteLine(arrayStack.Peek());

            Console.ReadLine();
        }
Example #3
0
        public static void Test()
        {
            LinkedStack <int> stack = new LinkedStack <int>();


            stack.Push(1);

            stack.Push(2);

            stack.Push(3);

            stack.Push(4);

            stack.Push(5);
        }
        static void Main(string[] args)
        {
            SimpleStack <int> myStack = new SimpleStack <int>();

            myStack.Push(1);
            myStack.Push(2);
            myStack.Push(3);

            var item       = myStack.Pop();
            var secondItem = myStack.Peek();

            Console.WriteLine(item);
            Console.WriteLine(secondItem);
            Console.ReadLine();

            Stack <double> stack = new Stack <double>();

            var linkedStack = new LinkedStack <int>();

            linkedStack.Push(10);
            linkedStack.Push(20);
            linkedStack.Push(30);
            linkedStack.Push(40);

            Console.WriteLine(linkedStack.Peek());
            Console.WriteLine(linkedStack.Pop());
            Console.WriteLine(linkedStack.Pop());
            Console.WriteLine(linkedStack.Peek());
            Console.ReadLine();

            var arrayStack = new ArrayStack <int>(5);

            arrayStack.Push(100);
            arrayStack.Push(200);
            arrayStack.Push(300);
            arrayStack.Push(400);
            arrayStack.Push(500);

            System.Console.WriteLine(arrayStack.Peek());
            System.Console.WriteLine(arrayStack.Pop());
            System.Console.WriteLine(arrayStack.Pop());
            System.Console.WriteLine(arrayStack.Peek());

            Console.ReadLine();
        }
Example #5
0
        static void Main(string[] args)
        {
            Model.EasyStack <int> easyStack = new Model.EasyStack <int>();

            easyStack.Push(1);
            easyStack.Push(2);
            easyStack.Push(3);

            var item  = easyStack.Pop();
            var item2 = easyStack.Peek();

            Console.WriteLine(item);
            Console.WriteLine(item2);
            Console.WriteLine();

            var linkedStack = new LinkedStack <int>();

            linkedStack.Push(10);
            linkedStack.Push(20);
            linkedStack.Push(30);
            linkedStack.Push(40);
            linkedStack.Push(50);

            Console.WriteLine(linkedStack.Peek());
            Console.WriteLine(linkedStack.Pop());
            Console.WriteLine(linkedStack.Pop());
            Console.WriteLine(linkedStack.Peek());
            Console.WriteLine();

            var arrayStack = new ArrayStack <int>(5);

            arrayStack.Push(100);
            arrayStack.Push(200);
            arrayStack.Push(300);
            arrayStack.Push(400);

            Console.WriteLine(arrayStack.Peek());
            Console.WriteLine(arrayStack.Pop());
            Console.WriteLine(arrayStack.Pop());
            Console.WriteLine(arrayStack.Peek());
            Console.ReadLine();
        }
Example #6
0
        static void Main(string[] args)
        {
            var easyStack = new EasyStack <int>();

            easyStack.Push(1);
            easyStack.Push(4);
            easyStack.Push(2);
            easyStack.Push(6);

            var item = easyStack.Pop();

            var item2 = easyStack.Peek();

            Console.WriteLine(item);
            Console.WriteLine(item2);

            Console.WriteLine();

            Stack <double> stack = new Stack <double>();

            var linkedStack = new LinkedStack <int>();

            var arrayStack = new ArrayStack <int>(5);

            arrayStack.Push(101);
            arrayStack.Push(10);
            arrayStack.Push(33);
            arrayStack.Push(20);
            arrayStack.Push(15);

            Console.WriteLine(arrayStack.Peek());
            Console.WriteLine(arrayStack.Pop());
            Console.WriteLine(arrayStack.Peek());

            Console.WriteLine(arrayStack.ToString());


            Console.ReadLine();
        }
Example #7
0
        public static void Main(string[] args)
        {
            // BCL中的Stack<T>

            //Stack<char> stack = new Stack<char>();

            // my array implement Stack
            //IStack<char> stack = new SequenceStack<char>(30);

            // linked list implement Stack
            IStack <char> stack = new LinkedStack <char>();

            stack.Push('G');
            stack.Push('a');
            stack.Push('b');
            stack.Push('w');
            Console.WriteLine(stack.Count);
            stack.Pop();
            Console.WriteLine(stack.Count);
            stack.Peek();
            Console.WriteLine(stack.Count);
            stack.Clear();
            Console.WriteLine(stack.Count);
        }