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

            一天一點(diǎn)

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

            常用鏈接

            留言簿(18)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            /*
            * 二分查找法
            *
            */


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

            using namespace std;


            int count = 0;
            /*
            輸入開始和長度,與長度除以2的元素對比,如果大于則將長度除以2的元素為開始,長度為 原長度除以2
            如果長度等于0,或者找到元素則返回;要注意在遞歸過程中 不要單獨(dú)使用一個(gè)一個(gè)的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 閱讀(194) 評論(0)  編輯 收藏 引用 所屬分類: C++知識

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            伊人久久无码中文字幕| 精品久久久久久无码专区| 久久精品国产亚洲77777| 91麻豆国产精品91久久久| 青青草原综合久久大伊人导航| 亚洲国产成人久久精品影视| 国产亚洲婷婷香蕉久久精品| 久久国产成人精品麻豆| 秋霞久久国产精品电影院| 国产成人精品久久一区二区三区av | 国产精品久久久久9999高清| 中文字幕亚洲综合久久菠萝蜜| 久久露脸国产精品| 婷婷久久五月天| 久久精品国产日本波多野结衣| 久久精品国产亚洲AV蜜臀色欲| 国产成人无码精品久久久性色| 久久综合精品国产二区无码| 九九久久自然熟的香蕉图片| 91精品国产综合久久四虎久久无码一级| 97久久天天综合色天天综合色hd| 久久精品国产亚洲av水果派 | 韩国无遮挡三级久久| 免费观看久久精彩视频| 久久国产香蕉一区精品| 狠狠精品久久久无码中文字幕| 精品蜜臀久久久久99网站| 久久久亚洲精品蜜桃臀| 精品久久久久久中文字幕大豆网| 伊人热人久久中文字幕| 香蕉99久久国产综合精品宅男自 | 久久男人AV资源网站| 欧美日韩精品久久免费| 狠狠干狠狠久久| 久久久久久久91精品免费观看| 久久亚洲春色中文字幕久久久| 久久国产高清一区二区三区| 无码久久精品国产亚洲Av影片| 久久久久18| 高清免费久久午夜精品| 久久精品国产亚洲AV不卡|