• <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精品国产自在现线 | 欧美国产精品久久高清| 久久一区二区免费播放| 伊人久久大香线蕉av不卡| 香蕉久久一区二区不卡无毒影院| 久久精品国产亚洲精品| 亚洲伊人久久大香线蕉综合图片| 日本精品久久久久中文字幕| 亚洲午夜精品久久久久久app| 久久婷婷五月综合97色| 人妻中文久久久久| 91久久香蕉国产熟女线看| 亚洲中文字幕无码久久综合网| 国产免费久久精品丫丫| 久久亚洲中文字幕精品有坂深雪| 久久久人妻精品无码一区| 久久精品国产精品青草app| 久久久久久精品免费看SSS| 国产精品综合久久第一页| 久久亚洲春色中文字幕久久久| 欧美性猛交xxxx免费看久久久| 7国产欧美日韩综合天堂中文久久久久 | 亚洲一区精品伊人久久伊人| 国产欧美一区二区久久| 亚洲欧美日韩久久精品第一区| 亚洲色欲久久久久综合网 | 99久久精品国产一区二区蜜芽 | 久久久WWW免费人成精品| 亚洲国产精久久久久久久| www性久久久com| 99久久免费国产精品热| 久久精品国产亚洲AV无码麻豆 | 99999久久久久久亚洲| 中文国产成人精品久久不卡| 伊人久久亚洲综合影院| 久久亚洲AV无码精品色午夜 | 久久se这里只有精品| 精品久久久久久国产牛牛app| 亚洲乱亚洲乱淫久久|