Exemplo n.º 1
0
    public static void Main()
    {
        Console.WriteLine("Hello World");

        var rS = new ResizingStack <int>();

        rS.push(1);
        rS.push(2);
        rS.push(12);
        rS.push(223);
        Console.WriteLine("=======");
        int i = rS.pop();

        Console.WriteLine("pop" + i);      //223
        i = rS.pop();
        Console.WriteLine("Pop" + i);      //12
        i = rS.pop();
        Console.WriteLine("Pop " + i);     //2
        i = rS.pop();
        Console.WriteLine("Pop " + i);     //1
    }
Exemplo n.º 2
0
        static void ResizingStackTest()
        {
            var stack = new ResizingStack <int>();

            Debug.Assert(stack.isEmpty());

            stack.push(8);
            Debug.Assert(!stack.isEmpty());
            Debug.Assert(1 == stack.size());

            stack.push(3);
            Debug.Assert(2 == stack.size());

            stack.push(-67);
            Debug.Assert(3 == stack.size());


            Debug.Assert(-67 == stack.pop());
            Debug.Assert(2 == stack.size());

            Debug.Assert(3 == stack.pop());
            Debug.Assert(1 == stack.size());

            Debug.Assert(8 == stack.pop());
            Debug.Assert(0 == stack.size());
            Debug.Assert(stack.isEmpty());
            try
            {
                stack.pop();
            }

            catch (System.Exception e)
            {
                Console.WriteLine("exception thrown:" + e.Message);
            }
        }