• <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>

            DraculaW

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              19 隨筆 :: 0 文章 :: 7 評論 :: 0 Trackbacks
            /////////////////////////////////////////////////////////////////////////////////

            // The Sort //

            // //

            /////////////////////////////////////////////////////////////////////////////////
            #ifndef _SORT_H_

            #define _SORT_H_
            /////////////////////////////////////////////////////////////////////////////////

            // The QuickSort //

            // //

            /////////////////////////////////////////////////////////////////////////////////
            template<typename T>

            int Quick(T* a, int s, int e)

            {

                T t = a[e];

                int i = s - 1;

                for(int j = s; j < e; j++ )

                    if(a[j] <= t)

                    {

                        i++;

                        swap(a[j],a[i]);

                    }



                    swap(a[i+1], a[e]);

                    return i+1;

            }
            template<typename T>

            void QuickSort(T* a, int s, int e)

            {

                if( s < e )

                {

                    int i = Quick(a, s, e);

                    //int i = part(a, s, e);

                    QuickSort(a, s, i-1);

                    QuickSort(a, i+1, e);

                }

            }
            /////////////////////////////////////////////////////////////////////////////////

            // The HeapSort //

            // //

            /////////////////////////////////////////////////////////////////////////////////

            inline int left(int i)

            {

                return 2*i+1;

            }
            inline int right(int i)

            {

                return 2*i+2;

            }
            template<typename T>

            void HeapHy(T* a, int n, int i)

            {

                int big = i;

                //first find the lage of i, left(i),right(i)

                if(left(i) < n)

                {

                    big = a[i]>a[left(i)]?(i):(left(i));

                    if(right(i) < n)

                        big = a[big]>a[right(i)]?(big):(right(i));

                }

                //and if the i not the biggest change pos i with the bigest

                if(i!=big)

                {

                    swap(a[i], a[big]);

                    //then HeapHy(a, n, bigest)

                    HeapHy(a, n, big);

                }

            }
            template<typename T>

            void BuildHeap(T* a, int n)

            {

                for(int i = n/2; i > -1; i--)

                    HeapHy(a, n, i);

            }
            template<typename T>

            void HeapSort(T* a, int n)

            {

                BuildHeap(a, n);

                for(int i=n-1; i>0; i--)

                {

                    swap(a[0], a[i]);

                    HeapHy(a, i, 0);

                }

            }
            /////////////////////////////////////////////////////////////////////////////////

            // The ShellSort //

            // //

            /////////////////////////////////////////////////////////////////////////////////
            template<typename T>

            void ShellSort(T* a, int s)

            {

                T t;

                int i,j,k;

                for(i=s/2; i>0; i=i/3)

                {

                    for(j=i; j<s; j++)

                    {

                        t = a[j];

                        for(k=j-i; k>-1; k-=i)

                        {

                            if(a[k]>t)

                                a[k+i] = a[k];

                        }

                        a[k+i] = t;

                    }

                }

            }
            #endif //_SORT_H_
            posted on 2007-11-15 20:27 DraculaW 閱讀(140) 評論(0)  編輯 收藏 引用
            国产99久久久国产精免费| 国产精品成人久久久久三级午夜电影 | 香港aa三级久久三级老师2021国产三级精品三级在 | 亚洲国产精品无码久久一区二区 | 97久久国产综合精品女不卡 | 久久99中文字幕久久| 亚洲国产精品久久| 久久本道久久综合伊人| 无码人妻久久一区二区三区蜜桃| 久久伊人五月丁香狠狠色| 欧美精品久久久久久久自慰| 久久精品99无色码中文字幕| 国内精品综合久久久40p| 93精91精品国产综合久久香蕉| 无码八A片人妻少妇久久| 欧美综合天天夜夜久久| 少妇无套内谢久久久久| 国产 亚洲 欧美 另类 久久| 亚洲中文字幕无码久久精品1 | 亚洲精品美女久久久久99小说 | 91精品国产91久久久久久青草| 亚洲人成电影网站久久| 国产亚洲精午夜久久久久久| 久久精品欧美日韩精品| 一本色道久久99一综合| 婷婷久久综合九色综合绿巨人| 精品久久香蕉国产线看观看亚洲 | 久久久噜噜噜久久中文字幕色伊伊| 久久久无码精品亚洲日韩蜜臀浪潮| 国产精品日韩欧美久久综合| 97超级碰碰碰久久久久| 亚洲AV日韩AV天堂久久| 午夜精品久久久久成人| 久久精品国产亚洲Aⅴ香蕉| 久久亚洲综合色一区二区三区| 潮喷大喷水系列无码久久精品| 亚洲精品国产美女久久久| 无码国产69精品久久久久网站| 国产精品久久久久久久久软件| 久久亚洲高清综合| 2021久久精品免费观看|