All pastes #184735 Raw Edit

Someone

public text v1 · immutable
#184735 ·published 2006-09-28 06:32 UTC
rendered paste body
        private string better_bubble_sort()
        {
            int temp = 0;
            int[] x = new int[Convert.ToInt32(textBox2.Text)];
            StringBuilder s2 = new StringBuilder();
            num_sort = 0;
            num_compare = 0;
            int counter = 0;
            for (int fill = Convert.ToInt32(textBox2.Text) - 1; fill >= 0; fill--)
            {
                x[fill] = my_array[fill];
            }
            int i = (Convert.ToInt32(textBox2.Text) - 1);
            bool swaps = true;
            //for (int i = (Convert.ToInt32(textBox2.Text) - 1); i >= 0; i--)
            while ((i >= 0) && (swaps == true))
            {
                swaps = false;
                for (int j = 1; j <= i; j++)
                {
                    num_compare++;
                    if (x[j - 1] > x[j])
                    {
                        swaps = true;
                        temp = x[j - 1];
                        x[j - 1] = x[j];
                        x[j] = temp;
                        counter++;
                        num_sort++;
                        if (counter == num)
                        {
                            // if none is clicked this works a little funny
                            // if there are more than the N changes it will showevery N times  
                            for (int m = 0; m < Convert.ToInt32(textBox2.Text); m++)
                            {
                                s2.Append(x[m] + " ");
                            }
                            s2.Append(Environment.NewLine);
                            counter = 0;
                        }
                    }
                }
                i--;
            }
            s2.Append(Environment.NewLine);
            for (int l = 0; l < Convert.ToInt32(textBox2.Text); l++)
            {
                s2.Append(x[l] + " ");
            }
            return s2.ToString();
        }