冒泡排序

void arrSort()
{
    int lengths = 10;
    int arr[10] = {9,19,2,3,1,61,21,4,1,11};
    int t;
    
    int m =0;
    /*
    while(m<lengths){
        for (int i =0;i < lengths-1; i++)
        {
            if(arr[i] > arr[i+1]){
                t = arr[i];
                arr[i] = arr[i+1];
                arr[i+1] = t;
            }
        }
        m++;
    }
    */

    
    for(;m<lengths;m++){
        for (int i =0;i <lengths-1-m; i++)
        {
            if(arr[i] > arr[i+1]){
                t = arr[i];
                arr[i] = arr[i+1];
                arr[i+1] = t;
            }
        }
    }

    int k =0;
    while(k < lengths){
        printf("%d --",arr[k]);
        k++;
    }
    


}
上一篇
数组越界
发表评论 / Comment

用心评论~