[C程式設計基礎]快速排序

來源:互聯網
上載者:User

標籤:意義   div   --   blog   log   程式   才有   遞迴   c程式設計   

//從大到小排序///三個參數 a要排序的 數組, l掃左邊的  r掃右邊void quickSort(int a[],int l, int r){    /// 左邊要小於 右邊才有意義    if (l < r){        //儲存 一下  ,基準定為X        int i = l, j = r;        int x = a[i];                ///左邊小於右邊才開始迴圈,排序裡面        while (i < j) {                        ///從 右邊開始向左尋找,大於等於 基準X的值。            while (i < j && a[j]<x)                j--;            if (i < j)                a[i++] = a[j];///調換 他們的值            ///該從左邊開始向右尋找 小於X的值            while (i < j && a[i]>x)                i++;            if (i < j)                a[j--] = a[i];        }        ///然後把 x的值 賦值回去        a[i] = x;        ///遞迴 左邊        quickSort(a, l, i-1);        ///右邊        quickSort(a, i+1, r);    }    }

  

[C程式設計基礎]快速排序

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.