You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
524 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
int main()
{
int a[100];
int i,j,k;
int n;
scanf("%d",&n);
for(i = 0;i < n;i++)
{
scanf("%d",&a[i]);
}
for(i = 0;i < n - 1;i++)
{
k = i;
for(j = i + 1;j < n;j++)
{
if(a[j] > a[k])
k = j;
}
if(i != k)
{
int t = a[i];
a[i] = a[k];
a[k] = t;
}
}
for(i = 0;i < n;i++)
{
printf("%d ",a[i]);
}
/**
时间复杂度: 选择法排序的时间复杂度为O(n2);
空间复杂度选择法排序的空间复杂度为S(n);
**/
}