예제 #1
0
        //Use my Stack class.
        public ListStack(Stack b)
        {
            listStack = new List<int>();    //Constructor for the List.
            stackPointer = 0;

            if (b != null)
            {
                int pointer2;
                int i = 0;

                int[] array = new int[10];

                pointer2 = b.GetCount();
                if (pointer2 > 0)
                {
                    i = 1;
                }

                while (pointer2 > 0)
                {
                    array[i] = b.Pop();
                    pointer2--;
                    i++;
                }
                i--;
                while (i > 0)
                {
                    this.Push(array[i]);
                    i--;
                }
            }
        }
예제 #2
0
        public ArrayStack(Stack b)
        {
            arrayStack = new int[10];   //Tis the the Array where the Values will be stored. Max 10 items.
            Pointer = 0;    //A pointer to keep track of where to Pop or Push the next Value.

            if (b != null)
            {
                int pointer2;
                int i = 0;

                int[] array = new int[10];

                pointer2 = b.GetCount();
                if (pointer2 > 0)
                {
                    i = 1;
                }

                while (pointer2 > 0)
                {
                    array[i] = b.Pop();
                    pointer2--;
                    i++;
                }
                i--;
                while (i > 0)
                {
                    this.Push(array[i]);
                    i--;
                }
            }
        }
예제 #3
0
        public MyListStack(Stack b)
        {
            linkedListStack = new LinkedList<int>();
            Pointer = 0;

            if (b != null)
            {
                int pointer2;
                int i = 0;

                int[] array = new int[10];

                pointer2 = b.GetCount();
                if (pointer2 > 0)
                {
                    i = 1;
                }

                while (pointer2 > 0)
                {
                    array[i] = b.Pop();
                    pointer2--;
                    i++;
                }
                i--;
                while (i > 0)
                {
                    this.Push(array[i]);
                    i--;
                }
            }
        }
예제 #4
0
 public bool ApplyModifiers(Stack stack, Modifier mod)
 {
     //This is used to perform the mathematical modifiers.
     int firstValue = stack.Pop();
     Program.form.listBox1.Items.Add("FirstValue is removed from stack.");
     int secondValue = stack.Pop();
     Program.form.listBox1.Items.Add("SecondValue is removed from stack.");
     if (mod == Modifier.Add){
         Push(firstValue+secondValue);
         Program.form.listBox1.Items.Add("Pushed " + (firstValue + secondValue) + " to stack.");
     }
     else if (mod == Modifier.Divide){
         if(secondValue == 0){
             Program.form.listBox1.Items.Add("Can't devide by zero.");
             return false;
         }
         Push(firstValue/secondValue);
         Program.form.listBox1.Items.Add("Pushed " + (firstValue / secondValue) + " to stack.");
     }
     else if (mod == Modifier.Multiply){
         Push(firstValue*secondValue);
         Program.form.listBox1.Items.Add("Pushed " + (firstValue * secondValue) + " to stack.");
     }
     else if (mod == Modifier.Subtract){
         Push(firstValue-secondValue);
         Program.form.listBox1.Items.Add("Pushed " + (firstValue - secondValue) + " to stack.");
     }
     else{
         Program.form.listBox1.Items.Add("Unknown modifier: " + mod); //Just to be sure.
         return false;
     }
     return true;
 }
예제 #5
0
 public void EmptyStack(Stack stack)
 {
     //To clear the stack just Pop every item in the stack.
     int max = stack.GetCount();
     for (int i = 0;i < max; i++){
         stack.Pop();
     }
 }
예제 #6
0
 public Form1()
 {
     currentStack = new ArrayStack(null);
     InitializeComponent();
     comboBox1.SelectedIndex = 0;
 }
예제 #7
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     //The dropdown Menu is used to select the right Stack Type.
     if (comboBox1.SelectedIndex == 0)
     {
         currentStack = new ArrayStack(currentStack);
     }
     else if (comboBox1.SelectedIndex == 1)
     {
         currentStack = new ListStack(currentStack);
     }
     else
     {
         currentStack = new MyListStack(currentStack);
     }
 }