Exemplo n.º 1
0
        /// <summary>
        /// If the radiobuttons are changed, the previous Stack will be reset and the new will be filled with new data.
        /// This method will be called twice. The first time it will reset and the second time it will fill in the new data.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void radioButtons_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton rb = (RadioButton)sender;

            // if the listbox contains some data, it will be stored in listBoxValues
            if (listBox.Items.Count > 0)
            {
                listBoxValues = listBox.Items.Cast <double?>().ToList();
                listBoxValues.Reverse(); // reverse the list so it can be added directly to the Stacks
            }

            // Do nothing if the listbox is empty
            if (listBoxValues != null)
            {
                if (rb.Checked)
                {
                    foreach (double?value in listBoxValues)
                    {
                        if (rb.Text == "MyListStack")
                        {
                            myListStack.Add(0, value);
                        }
                        else if (rb.Text == "ArrayStack")
                        {
                            arrayStack.Add(0, value);
                        }
                        else
                        {
                            listStack.Add(0, value);
                        }
                    }
                }
                else
                {
                    if (rb.Text == "MyListStack")
                    {
                        myListStack.Reset();
                    }
                    else if (rb.Text == "ArrayStack")
                    {
                        arrayStack.Reset();
                    }
                    else
                    {
                        listStack.Reset();
                    }
                }
            }
            UpdateListBox();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a new item to the MyListStack
 /// </summary>
 /// <param name="index"></param>
 /// <param name="value">The value that needs to be added</param>
 public void Add(int index, double?value)
 {
     // stop condition
     if (item == null)
     {
         item = value;
     }
     else if (next == null)
     {
         next      = new MyListStack <T>();
         next.item = item;
         item      = null;
         Add(0, value);
     }
     else
     {
         next.Add(0, item);
         item = value;
     }
 }