Exemplo n.º 1
0
        //============================================================================================================================================================
        private void StackOperationsDemoButton_Click(object sender, RoutedEventArgs e)
        {
            StackOperations StackDemoObj = new StackOperations();
            //StackDemoObj.StackOperationsDemo();

            StackOperations StackOperationsObj = new StackOperations();

            StackOperationsObj.PushPopGetMinWithConstantTime();

            StackOperations.ReturnSameStackInReverseOrder();

            StackOperations.RunTowersOfHanoiMoveWithOutStack();
        }
        public void StackOperationsDemo()
        {
            StringBuilder outputString = new StringBuilder();

            outputString.Append("Stack Operations with Arrays.");
            StackOperations StackDemoObject = new StackOperations();

            // 1. Initialize stack pointer.
            StackDemoObject.InitializeStack(3);

            // 2. Push elements into stack.
            StackDemoObject.PushElementToStack(1);
            StackDemoObject.PushElementToStack(2);
            StackDemoObject.PushElementToStack(3);

            outputString.Append(Environment.NewLine + Environment.NewLine + "Data inserted into stack.");

            if (StackDemoObject.IsStackFull())
            {
                outputString.Append(Environment.NewLine + Environment.NewLine + "Stack is full." + Environment.NewLine);
            }

            // 3. Pop elements from stack.
            while (!StackDemoObject.IsStackEmpty())
            {
                int element = StackDemoObject.PopElementFromStack();
                outputString.Append(Environment.NewLine + element + " Poped element from stack.");
            }

            // 4. Check If stack is empty.
            if (StackDemoObject.IsStackEmpty() == true)
            {
                outputString.Append(Environment.NewLine + Environment.NewLine + "Stack is empty.");
            }

            MessageBox.Show(Convert.ToString(outputString));
        }