定义函数voidsort(int a[ ],int n),用选择法对数组a中的元素升序排列。

日期:2010-06-06 10:15:46 人气:1

定义函数voidsort(int a[ ],int n),用选择法对数组a中的元素升序排列。

void sort(int a[], int n) { for(int i=0;i<n-1;i++) { int r = i; for(int j=i+1;j<n;j++) { if(a[j]<a[r]) r = j; } int temp = a[i]; a[i] = a[r]; a[r] = temp; } }
    A+
热门评论