Exemplo n.º 1
0
 static void Main(string[] args)
 {
     NewStack<int> stack = new NewStack<int>();
     stack.Push(4);
     stack.Push(5);
     stack.Push(6);
     Console.WriteLine(stack.Peek());
     int element = stack.Pop();
     Console.WriteLine(stack.Peek());
     Console.WriteLine(stack.Count);
 }
Exemplo n.º 2
0
    static void Main(string[] args)
    {
        NewStack <int> intStack = new NewStack <int>(10);

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

        Console.WriteLine(intStack.Pop());
        Console.WriteLine(intStack.Pop());
        Console.WriteLine(intStack.Pop());
    }
Exemplo n.º 3
0
        private void myAddValueButton_Click(object sender, EventArgs e)
        {
            myNumberOfValue = Convert.ToInt32(myInputValueTextBox.Text);
            if (choosingMyProjectComboBox.Text == "My Stack")
            {
                Stopwatch watchNewDynamicStack = Stopwatch.StartNew();
                for (int i = 0; i < myNumberOfValue; i++)
                {
                    newDynamicStack.Push(i);
                }
                watchNewDynamicStack.Stop();
                updateMyTimeLableForAddingValue(watchNewDynamicStack);
                redrawNewDynamicStack();
            }

            if (choosingMyProjectComboBox.Text == "My Queue")
            {
                Stopwatch watchNewDynamicQueue = Stopwatch.StartNew();
                for (int i = 0; i < myNumberOfValue; i++)
                {
                    newDynamicQueue.EnQueue(i);
                }
                watchNewDynamicQueue.Stop();
                updateMyTimeLableForAddingValue(watchNewDynamicQueue);
                redrawNewDynamicQueue();
            }
        }
Exemplo n.º 4
0
        public static void Main()
        {
            NewStack<int> stack = new NewStack<int>(4);

            Console.WriteLine("Testing adding:");
            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            Console.WriteLine(stack);
            Console.WriteLine();

            Console.WriteLine("Testing resizing:");
            stack.Push(4);
            stack.Push(5);
            Console.WriteLine(stack);
            Console.WriteLine();

            Console.WriteLine("Testing peeking:");
            Console.WriteLine(stack.Peek());
            Console.WriteLine(stack.Peek());
            Console.WriteLine();

            Console.WriteLine("Testing popping:");
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack);
            Console.WriteLine();

            Console.WriteLine("Testing contains:");
            Console.WriteLine("The stack contains 2: {0}", stack.Contains(2));
            Console.WriteLine("The stack contains 164: {0}", stack.Contains(164));
            Console.WriteLine();

            Console.WriteLine("Testing clearing:");
            stack.Clear();
            Console.WriteLine(stack);
        }
        public static void StackTest()
        {
            Stack <int> stack = new Stack <int>();

            stack.Push(1);
            stack.Push(2);
            var x = stack.Pop();

            Console.WriteLine(x);

            NewStack <int> newStack = NewStack <int> .Empty();

            newStack = NewStack <int> .Push(newStack, 1);

            newStack = NewStack <int> .Push(newStack, 2);

            (x, newStack) = NewStack <int> .Pop(newStack);

            Console.WriteLine(x);
        }
        public static void Main()
        {
            var myStack = new NewStack<int>();
            try
            {
                Console.WriteLine(myStack.Pop());
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("Index = 0 => exception");
            }

            myStack.Push(1);
            myStack.Push(2);
            myStack.Push(3);
            myStack.Push(4);
            myStack.Push(5);
            myStack.Push(6);
            myStack.Push(7);

            Console.WriteLine("Last item -> " + myStack.Peek());
            Console.WriteLine("All items -> " + string.Join(", ", myStack));
        }