Ejemplo n.º 1
0
        private void btnSort_Click(object sender, EventArgs e)
        {
            int[] selSort = new int[stackCount];
            int   i = 0, j, k, minVal, temp;

            MyLList.Node node = stackList.Last; // First in last out. Our last node is our Top of Stack. So we start from the end and go back.
            while (node != null)
            {
                selSort[i] = node.Data;
                for (j = 0; j < i; j++)
                {
                    minVal = j;
                    for (k = j + 1; k <= i; k++)
                    {
                        if (selSort[k] < selSort[j])
                        {
                            minVal = k;
                        }
                    }
                    temp            = selSort[minVal];
                    selSort[minVal] = selSort[j];
                    selSort[j]      = temp;
                }
                i++;
                node = node.Previous;
                printList(selSort, i);
                messageString = messageString + i + ". iterative " + lblSortedNumbers.Text + "\n";
            }
            MessageBox.Show(messageString, "Result of iterative selection sort");
            messageString = "";
        }
Ejemplo n.º 2
0
        private void btnAddNumber_Click(object sender, EventArgs e)
        {
            int newNumber;

            if (!int.TryParse(txtNewNumber.Text, out newNumber))
            {
                MessageBox.Show("Please make sure that you have entered numeric value!", "Error on conversion");
                return;
            }

            MyLList.Node node = new MyLList.Node(newNumber);
            insertion(node);
            lblNumberList.Text = lblNumberList.Text + " " + newNumber;
            txtNewNumber.Clear();
        }
Ejemplo n.º 3
0
        private void btnAddNumber_Click(object sender, EventArgs e)
        {
            int newNumber;

            if (!int.TryParse(txtNewNumber.Text, out newNumber))
            {
                MessageBox.Show("Please enter only numeric values.", "Error!");
                return;
            }

            MyLList.Node node = new MyLList.Node(newNumber);
            toTheStack(node);
            lblStack.Text = lblStack.Text + " " + newNumber;
            txtNewNumber.Clear();
        }
Ejemplo n.º 4
0
 public void toTheStack(MyLList.Node node)
 {
     if (stackList.First == null)
     {
         stackList.First = node;
         stackList.Last  = node;
         stackCount++;
     }
     else
     {
         stackList.Last.Next = node;
         node.Previous       = stackList.Last;
         stackList.Last      = node;
         stackCount++;
     }
 }
Ejemplo n.º 5
0
 public void insertion(MyLList.Node node)
 {
     if (someList.First != null)
     {
         someList.Last.Next = node;
         node.Previous      = someList.Last;
         node.Next          = null;
         someList.Last      = node;
     }
     else
     {
         someList.First          = node;
         someList.Last           = node;
         someList.First.Previous = null; //Just to make sure that no one is connected after or before my first and last nodes.
         someList.Last.Next      = null;
     }
 }
Ejemplo n.º 6
0
 public void divideThemAll()
 {
     MyLList.Node node = someList.First;
     while (node != null)
     {
         dividedSpecs = dividedSpecs + "Exact dividers of " + node.Data + " are: ";
         for (int i = 1; i <= node.Data; i++)
         {
             if (node.Data % i == 0)
             {
                 dividedSpecs = dividedSpecs + i + " ";
             }
         }
         dividedSpecs = dividedSpecs + "\n";
         node         = node.Next;
     }
     MessageBox.Show(dividedSpecs, "Result of linear search");
 }
Ejemplo n.º 7
0
        private void btnRecSort_Click(object sender, EventArgs e)
        {
            int i = 0;

            int[]        selSort = new int[stackCount];
            MyLList.Node node    = stackList.Last;
            while (node != null)
            {
                selSort[i] = node.Data;
                recSelSort(selSort, i);
                i++;
                node = node.Previous;
                printList(selSort, i);
                messageString = messageString + i + ". iterative " + lblSortedNumbers.Text + "\n";
            }
            MessageBox.Show(messageString, "Result of recursive selection sort");
            messageString = "";
        }
Ejemplo n.º 8
0
 public void recLinearSearch(MyLList.Node node, int key)
 {
     if (node == null)
     {
         dividedSpecs = "Sorry but the key you're looking for is not in the list. \n";
         MessageBox.Show(dividedSpecs, "Search result");
     }
     else
     {
         if (node.Data == key)
         {
             dividedSpecs = "Conguratulations! This key is in the list!\n";
             divideThemAll();
             return;
         }
         else
         {
             recLinearSearch(node.Next, key);
         }
     }
 }