使用函数/方法 调用冒泡排序
class Program
{
private static void Sort(int[] sortArray)//定义一个冒泡排序的方法
{
bool swapped = true;
do {
swapped = false;
for (int i = 0; i < sortArray.Length - 1; i++)
{
if (sortArray[i] > sortArray[i + 1])
{
int temp = sortArray[i];
sortArray[i] = sortArray[i + 1];
sortArray[i + 1] = temp;
swapped = true;
}
}
} while (swapped);
}
static void Main(string[] args)
{
int[] sortArray = { 22,5,63,91,2,48,151,6,49,73 };
Sort(sortArray);//调用冒泡排序
foreach (int temp in sortArray)
{ Console.WriteLine(temp); }
}
}