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

            一天一點

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              13 Posts :: 7 Stories :: 3 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(18)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            /*
            * 二分查找法
            *
            */


            #include 
            <iostream>
            #include 
            <windows.h>

            using namespace std;


            int count = 0;
            /*
            輸入開始和長度,與長度除以2的元素對比,如果大于則將長度除以2的元素為開始,長度為 原長度除以2
            如果長度等于0,或者找到元素則返回;要注意在遞歸過程中 不要單獨使用一個一個的if 最好是 if else
            */

            int half(int begin[],int icount,int value);

            int main()
            {
                cout 
            << "Hello world!" << endl;
                
            int array[100];
                
            for (int i = 0;i < 100;i++)
                
            {
                    array[i] 
            = i+100;
                    cout 
            <<"array["<<i<<"] = "<<array[i] <<endl;
                }

                
            int result;
                result 
            = half(array,100,99);
                cout
            << "result = " <<result <<endl;
                system(
            "pause");
                
            return 0;
            }


            int half(int begin[],int icount,int value)
            {
                count
            ++;
                cout
            << "count : " <<count<<endl;
                
            /*
                if (value == *begin)
                {
                    return *begin;
                }
                
            */

                
            if (value == begin[icount])
                
            {
                    
            return begin[icount];
                }

                
            else if (icount == 0)
                
            {
                    
            return -1;
                }

                
            else if (value == begin[icount / 2])
                
            {
                    
            return begin[icount / 2];
                }

                
            else if (value < begin[icount / 2])
                
            {
                    half(begin,icount 
            / 2,value);
                }

                
            else if (value > begin[icount / 2])
                
            {
                    half(
            &begin[icount / 2],icount / 2,value);
                }

            }

            posted on 2010-05-18 23:08 billow 閱讀(200) 評論(0)  編輯 收藏 引用 所屬分類: C++知識
            99re这里只有精品热久久| 伊人久久久AV老熟妇色| 麻豆AV一区二区三区久久| 精品久久久久久国产三级 | 久久妇女高潮几次MBA| 久久精品国产精品青草| 91久久精品电影| 国产成人精品久久综合 | 2020久久精品国产免费| 久久亚洲综合色一区二区三区| 无码AV波多野结衣久久| 久久久一本精品99久久精品66| 超级97碰碰碰碰久久久久最新| 欧美日韩精品久久免费| 久久国产亚洲精品无码| 午夜精品久久久内射近拍高清| 亚洲精品乱码久久久久久中文字幕| 久久精品国产清高在天天线| 99久久无码一区人妻| 无码人妻精品一区二区三区久久| 91视频国产91久久久| 伊人色综合久久天天人手人婷| 久久美女人爽女人爽| 青青热久久综合网伊人| 人妻精品久久无码区| 狠狠色婷婷久久综合频道日韩| 青青青青久久精品国产h久久精品五福影院1421 | 国产亚洲色婷婷久久99精品| 日日狠狠久久偷偷色综合免费| 好久久免费视频高清| 日韩欧美亚洲综合久久影院d3| 久久国产色av免费看| 精品永久久福利一区二区| 国产情侣久久久久aⅴ免费| 国产成人久久激情91| 国产精品久久网| 国产色综合久久无码有码| 久久综合亚洲欧美成人| 九九久久99综合一区二区| 国内精品久久久久久久久| 亚洲国产精久久久久久久|