using System.Collections.Specialized;
using System.Threading;
using System.Xml.Linq;
namespace 结构体
{
class Program {
static void Main(String[] args)
{
bool judge = false;
int t = 0;
Random random = new Random();
int[] arr=new int[20];
for(int i = 0; i < arr.Length; i++)
{
arr[i]=random.Next(1,15);
}
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i]+",");
}
Console.WriteLine();
Console.WriteLine("{0}排序", judge);
int suol = 0;
for (int i = 0; i < arr.Length ; i++)
{
suol = 0;
for (int j = 0; j < arr.Length - i; j++)
{
if (arr[j] > arr[suol])
{
suol = j;
}
}
if (suol != arr.Length - 1 - i)
{
t = arr[arr.Length - 1 - i];
arr[arr.Length - 1 - i] = arr[suol];
arr[suol] = t;
}
}
Console.WriteLine("结果");
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + ",");
}
}
}
}
C# 选择排序
最新推荐文章于 2024-09-13 15:26:39 发布