コード例 #1
0
        /// <summary>
        /// Adds value to the current stack
        /// </summary>
        public void AddToStack(bool getLastResult = false)
        {
            double input;

            if (getLastResult)
            {
                // Get last calculated value
                input = lastResult.GetValueOrDefault();
            }
            else
            {
                string currentInput       = labelInput.Text;
                bool   successfullyParsed = double.TryParse(currentInput, out input);

                // Check if set value is valid
                if (currentInput == "" || !successfullyParsed)
                {
                    return;
                }
            }

            // Add value to listbox and update it
            listBoxValues.Add(input);
            UpdateListBox();

            // Add to stack
            switch (array)
            {
            case "ArrayStack":
                arrayStack.Add(input);
                break;

            case "ListStack":
                listStack.Add(input);
                break;

            case "MyListStack":
                myListStack.Add(input);
                break;

            default:
                break;
            }

            // Clear input field
            labelInput.Text = "";
        }
コード例 #2
0
ファイル: MyListStack.cs プロジェクト: Robske/StackCalculator
 // Explained in Stack class
 public override void Add(double?value)
 {
     if (item == null)
     {
         item = value;
     }
     else if (next == null)
     {
         // Create next and set item by calling Add
         next = new MyListStack();
         next.Add(value);
     }
     else
     {
         next.Add(value);
     }
 }