标签:main void return bsp printf pre div 选择排序 include
思路:每次找出数组中最大的数,放到后面。
1 #include<stdio.h> 2 3 int max_index(int a[], int len); 4 int main(void) 5 { 6 int a[] = { 2,45,6,12,87,34,90,24,23,11,65 }; 7 int len = sizeof(a) / sizeof(a[0]); 8 9 for (int i = len; i > 1; i--) 10 { 11 int t = a[i - 1]; 12 a[i - 1] = a[max_index(a, i)]; 13 a[max_index(a, i)] = t; 14 } 15 16 for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++) 17 { 18 printf("%d\t", a[i]); 19 } 20 } 21 22 int max_index(int a[], int len) 23 { 24 int ret = 0; 25 26 for (int i = 1; i < len; i++) 27 { 28 if (a[i] > a[ret]) 29 { 30 ret = i; 31 } 32 } 33 34 return ret; 35 }
标签:main void return bsp printf pre div 选择排序 include
原文地址:https://www.cnblogs.com/2018jason/p/12020513.html