數組元素倒置

    // for 循環
    for (int start = 0,end = len-1; start < end; start++,end--) {
        int temp = a[start];
        a[start] = a[end];
        a[end] = temp;
    }
    
    // while循環
    int start = 0;
    int end = len-1;
    while(start < end){
        int temp = a[start];
        a[start] = a[end];
        a[end] = temp;
        
        start++;
        end--;
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章