Example #1
0
 public static void Main(string[] args)
 {
     Stack<int> stack = new Stack<int>();
     stack.Push(1);
     stack.Push(2);
     stack.Push(3);
     Console.WriteLine(stack.Pop());
     Console.WriteLine(stack.Peek());
 }
        public static void Main()
        {
            // The initial value of the array is 4. If we add 5 elements it should resize to 8.
            var stack = new Stack<int>();

            Console.WriteLine("Adding 1,2,3,4,5");
            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            stack.Push(4);
            stack.Push(5);

            Console.WriteLine("Peeking last added number: {0}", stack.Peek());
            Console.WriteLine("Popping number: {0}", stack.Pop());
            Console.WriteLine("Popping number: {0}", stack.Pop());
            Console.WriteLine("Peeking number: {0}", stack.Peek());

            Console.WriteLine("Pushing number 6");
            stack.Push(6);

            Console.WriteLine("Peeking number: {0}", stack.Peek());
        }
Example #3
0
        public static void Main(string[] args)
        {
            var stack = new Stack<int>();
            Console.WriteLine(stack);
            stack.Push(1);
            Console.WriteLine(stack);
            stack.Push(2);
            Console.WriteLine(stack);
            stack.Push(3);
            Console.WriteLine(stack);
            stack.Push(4);
            Console.WriteLine(stack);
            stack.Push(5);
            Console.WriteLine(stack);
            stack.Push(6);
            Console.WriteLine(stack);

            Console.WriteLine("Containes(4): {0}", stack.Contains(4));
            Console.WriteLine("Containes(7): {0}", stack.Contains(7));

            // stack.Clear();
            // Console.WriteLine(stack);
            stack.Pop();
            stack.Pop();
            stack.Pop();
            stack.Pop();
            Console.WriteLine(stack);
            stack.TrimExcess();
            Console.WriteLine(stack);
            stack.Pop();
            Console.WriteLine(stack);
            Console.WriteLine("Peek() => {0}\n", stack.Peek());
            Console.WriteLine(stack);

            // stack.Pop();
            // Console.WriteLine(stack);
            // stack.Pop();
            // Console.WriteLine(stack);
        }