• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天之道

            享受編程的樂趣。
            posts - 118, comments - 7, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            快速排序

            Posted on 2012-05-08 17:11 hoshelly 閱讀(133) 評論(0)  編輯 收藏 引用 所屬分類: Programming
            輸入

            第一行包含一個整數T,表示有T組數據。對于每組數據:第一行包含一個數字N(<100),表示該組數據由N個元素;第二行包含N個數,就是這N個元素的值( <10000 )。

            輸出

            對于每組數據輸出一行,包含排序好后的N個元素,要求從小到大排序,相鄰2個元素間有個空格,末尾無空格有個回車。

            樣例輸入
            1 3 1 3 2
            樣例輸出
            1 2 3


            #include<stdio.h>
            void swap(int a[],int low,int high)
            {
                
            int temp=a[low];
                a[low]
            =a[high];
                a[high]
            =temp;
            }

            int partition(int a[],int low,int high)
            {
                
            int pivotkey=a[low];
                
            while(low<high)
                {
                    
            while(low<high && a[high]>=pivotkey)
                        high
            --;
                    swap(a,low,high);
                    
            while(low<high && a[low]<=pivotkey)
                        low
            ++;
                    swap(a,low,high);
                }
                
            return low;
            }

            void qsort(int a[],int low,int high)
            {
                
            int pivot;
                
            if(low<high)
                {
                    pivot
            =partition(a,low,high);
                    qsort(a,low,pivot
            -1);
                    qsort(a,pivot
            +1,high);
                }
            }


            int main()
            {
                
            int n,m,i,a[102];
                scanf(
            "%d",&n);
                
            while(n--)
                {
                    scanf(
            "%d",&m);
                    
            for(i=0;i<m;i++)
                    {
                        scanf(
            "%d",&a[i]);
                    }

                    qsort(a,
            0,m-1);

                        
                    
            for(i=0;i<m;i++)
                    {
                        printf(
            "%d ",a[i]);
                    }
                    printf(
            "\n");

                }

                
            return 0;
            }
            久久国产精品一区二区| 亚洲午夜久久久久久久久电影网 | 午夜精品久久久久久中宇| 少妇久久久久久被弄到高潮 | www.久久热| 欧洲性大片xxxxx久久久| 亚洲天堂久久精品| 精品国产乱码久久久久久呢| 午夜精品久久久久久久| 精品水蜜桃久久久久久久| 精品久久人人爽天天玩人人妻| 99久久99久久久精品齐齐| 久久久精品视频免费观看| 久久综合九色综合网站| 天天综合久久一二三区| 国产欧美久久一区二区| 欧美精品国产综合久久| 国产毛片久久久久久国产毛片| 国产精品久久久久a影院| 精品多毛少妇人妻AV免费久久| 99久久国产宗和精品1上映 | 97久久精品人人澡人人爽| 亚洲精品tv久久久久久久久| 精品综合久久久久久88小说 | 久久久久99精品成人片| 国产精品美女久久久久| 亚洲精品tv久久久久久久久| 狠狠色丁香久久婷婷综合图片| 国产高潮久久免费观看| 久久被窝电影亚洲爽爽爽| 韩国免费A级毛片久久| 久久久久亚洲AV成人网人人网站| 国产福利电影一区二区三区久久久久成人精品综合 | 亚洲国产精品无码久久青草 | 久久久精品人妻无码专区不卡| 99久久久国产精品免费无卡顿| 精品久久人人爽天天玩人人妻| 久久亚洲精品无码VA大香大香| 亚洲国产综合久久天堂| 97视频久久久| 久久久久人妻精品一区二区三区 |