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();
}
private string smarter_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))
{
//MessageBox.Show(i.ToString());
swaps = false;
for (int j = (Convert.ToInt32(textBox2.Text)-i); 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;
}
}
}
//******************************************************************************
for (int j = (i-1); j >= (Convert.ToInt32(textBox2.Text) -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=i-2;
//textBox3.AppendText(s2.ToString() + Environment.NewLine + Environment.NewLine);
}
s2.Append(Environment.NewLine);
for (int l = 0; l < Convert.ToInt32(textBox2.Text); l++)
{
s2.Append(x[l] + " ");
}
return s2.ToString();
}