Monday, March 23, 2009

bubble sort in C#

int[] number = { 1, 6, 3, 9, 2, 8 };
int temp =0;

for (int i = number.Length ; i>=1; i--)
{
for (int j = 0; j < i-1; j++)
{
if (number[j]>number[j+1])
{
temp = number[j+1];
number[j + 1] = number[j];
number[j] = temp;

}
}
}

// Display the result in the messageBox
for (int i = 0; i < number.Length; i++)
{
MessageBox.Show(number[i].ToString());
}

No comments:

Post a Comment

5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...