冒泡排序
int[] arrs = { 65, 97, 76, 13, 27, 49, 58 };
bool isdel;
int count = 0;//内循环次数
for (int i = 0; i < arrs.Length - 1; i++)
{
isdel = true;
for (int j = 0; j < arrs.Length - 1 - i; j++)
{
count++;
if (arrs[j] > arrs[j + 1])
{
isdel = false;
int tmp = arrs[j];
arrs[j] = arrs[j + 1];
arrs[j + 1] = tmp;
}
}
if (isdel)//如果为true说明排序完成
{
break;
}
}
for (int i = 0; i < arrs.Length; i++)
{
Console.Write(arrs[i] + " ");
}
Console.WriteLine("循环次数:" + count);