冒泡排序算法 ,用C#語言實現
public static int[] BubbleSort(int[] SArr)
{
int[] Arr = SArr;
int length = Arr.Length;
for (int i = 0; i < length - 1; i++)
{
for (int j = i + 1; j < length; j++)
{
if (Arr[i] > Arr[j])
{
Arr[i] = Arr[i] + Arr[j];
Arr[j] = Arr[i] - Arr[j];
Arr[i] = Arr[i] - Arr[j];
}
}
}
return Arr;
}