标签:csharp next int 复杂度 read ati for div static
while (true)
{
int.TryParse(Console.ReadLine(), out int N);
int[] arr = new int[N];
Random ran = new Random();
for (int i = 0; i < arr.Length; i++)
{
arr[i] = ran.Next(1, 1000);
}
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
Sort(arr);
Console.WriteLine($"第{N / 2}大的数为:" + arr[N / 2 - 1]);
stopwatch.Stop();
TimeSpan tp = stopwatch.Elapsed;
Console.WriteLine($"程序运行:总毫秒:{tp.TotalMilliseconds}");
}
//从大到小
static int[] Sort(int[] arr)
{
int temp;
for (int i = 0; i < arr.Length - 1; i++)
{
for (int j = i + 1; j < arr.Length; j++)
{
if (arr[i] < arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
return arr;
}
用最简单的数组索引返回k最大值,时间复杂度惨不忍睹。
标签:csharp next int 复杂度 read ati for div static
原文地址:https://www.cnblogs.com/Icecoldless/p/11038134.html