冒泡排序-fusha
class Program
{
static void Main(string[] args)
{
Console.WriteLine("冒泡排序算法演示:--------------------");
int[] Text = { 5, 8, 2, 11, 20, 1, 3, 6 };
bubble_sort(ref Text);
for (int i = 0; i < Text.Length; i++)
{
Console.WriteLine("冒泡排序结果:"+Text[i]);
}
Console.ReadLine();
}
public static void bubble_sort(ref int [] ary )//冒泡排序函数
{
int temp;
for (int i = 0; i < ary.Length; i++)//总有多少个数就换值判断多少次,确保每一次都是正确的。第一个值小于第二个值。
{
for (int j = i+1; j < ary.Length; j++)
{
if (ary[j]<ary[i])//判断第二个数是否小于第一个数,如果是则发生换值。
{
temp = ary[j];
ary[j] = ary[i];
ary[i] = temp;
}
}
}
}
}
}