2.31 model - array sort function

[Note: This program is verified using vs2013 version]

 

#include <stdio.h> 
#include < String .h> 
#include <stdlib.h>
 / * 
     here NOTE: 
     If the array as a function of the parameter, a pointer array parameter degradation (mainly to high) 
     so here parameter * src, src [], as src [1] the practical effect of 
* / 
int sort_array ( int * the src, int length) { 
     int   I, J, TEMP, RET;
     int * from = the src; // if this is provided as a global variable better? 
    IF ( from == 0 ) {         return - . 1 ;} 
    
    for (I = 0 ; I <length - . 1; i++){//选择法排序
        for (j = i + 1; j < length; j++){
            if (from[i] > from[j]){
                temp = from[j];
                from[j] = from[i];
                from[i] = temp;
            }
        }
    }
    return 0;
}


int main(void){
    int a[] = { 10, 7, 1, 9, 4, 6, 7, 3, 2, 0 };
    int i = 0;
    int length = sizeof(a) / sizeof(a[0]);
    int ret = 0;

    printf("排序前");
    for (i = 0; i < length; i++){
        printf("%d  ", a[i]);
    }
    printf("\n");
   RET
= sort_array (A, length); // parameters: the name of the array to be sorted length IF (! RET = 0 ) { return ; } (the printf " sorted " ); for (I = 0 ; I <length; I ++ ) { the printf ( " % D " , A [I]); }
   the printf (
" \ n- " ); System ( " PAUSE " ); return 0 ; }

 

Guess you like

Origin www.cnblogs.com/wlstm/p/11105489.html