public static void ReOrderByPop(int[] arr)//冒泡降序
{
for (int i = 0; i < arr.Length - 1; i++)
{
for (int j = 0; j < arr.Length - 1 - i; j++)
{
if (arr[j] < arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
public static void ReOrderBySelect(int[] arr)
{
int index = 0;
for (int i = 0; i < arr.Length-1; i++)
{
index = i;
for (int j = index+1; j <arr.Length; j++)
{
if (arr[j]>arr[index])
{
index = j;
}
}
int temp = arr[index];
arr[index] = arr[i];
arr[i] = temp;
}
}
static void ShowArr(int[]arr)
{
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i]+" ");
}
Console.WriteLine();
}
static void Main(string[] args)
{
int[] arr = { 1, 2, 3, 54, 48, 56, 24, 14, 84 };
ReOrderByPop(arr);
ShowArr(arr);
ReOrderBySelect(arr);
ShowArr(arr);
}