冒泡排序:
namespace BubbleSorter
{
public class BubbleSorter
{
static void Main(string[] args)
{
int[] arr = new int[] {50,6,45,94,78};
BubbleSorter sh = new BubbleSorter();
sh.Sort(arr);
for (int m = 0; m < arr.Length; m++)
Console.Write(" {0} ", arr[m]);
Console.WriteLine();
Console.ReadLine();
}
public void Sort(int[] list)
{
int i, j, temp;
j = 1;
for (i = 0; i < list.Length - j; i++)
{
if (list[i] > list[i + 1])
{
temp = list[i];
list[i] = list[i + 1];
list[i + 1] = temp;
}
}
j++;
}
}
}
浙公网安备 33010602011771号