冒泡排序
int[] aaa = { 5, 12, 3, 52, 2, 67 };
for (int j = 0; j <= aaa.Length; j++)
{
for (int i = 1; i < aaa.Length; i++)
{
int temp;
if (aaa[i] > aaa[i - 1])
{
temp = aaa[i];
aaa[i] = aaa[i - 1];
aaa[i - 1] = temp;
}
}
}
foreach (int item in aaa)
{
Console.Write(item + " ");
}
顺序排序
int[] numbs = { 3,2,9,7,5,6};
int temp = 0;
for (int i = 0; i < numbs.Length; i++)
{
for (int j = i+1; j < numbs.Length; j++)
{
if (numbs[j]>numbs[i])
{
temp = numbs[j];
numbs[j] = numbs[i];
numbs[i] = temp;
}
}
}
foreach (int item in numbs)
{
Console.Write(item+",");
}