冒泡:
public static void MaoPao()
{
int[] arrList = { 1, 2, 6, 8, 3, 4, 5,12,9,14,29,16 };
for (int i = 0; i < arrList.Length ; i++)
{
int temp = arrList[i];
for (int j = i + 1; j < arrList.Length; j++)
{
if (temp > arrList[j])
{
arrList[i] = arrList[j];
arrList[j] = temp;
temp = arrList[i];
}
}
}
foreach (var item in arrList)
{
Console.WriteLine("冒泡结果{0}", item);
}
int[] arr = { 1, 2, 6, 8, 3, 4, 5, 12, 9, 14, 29, 16 };
for (int i = 0; i <= arr.Length - 1; i++)
{
for (int j = arr.Length - 1; j > i; j--)
{
if ((int)arr[j] < (int)arr[j - 1])
{
int temp = (int)arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
}
foreach (var item in arr)
{
Console.WriteLine("冒泡结果{0}", item);
}
}