• <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 - 71,  comments - 41,  trackbacks - 0
            接著來(lái)個(gè)無(wú)回溯的,一般教科書上都是用KMP作case的,這里給個(gè)平均效率更好的Boyer-Moore Algorithm實(shí)現(xiàn)
            ?1 #include? < cstring >
            ?2 int ?BM( const ? char ? * text,? const ? char ? * pattern)
            ?3
            {
            ?4 ???? int ?arrShiftTable[ 256
            ];
            ?5 ???? int ?tLen? =
            ?strlen(text);
            ?6 ???? int ?pLen? =
            ?strlen(pattern);
            ?7 ???? int
            ?currPos,?tReadPos,?pReadPos;
            ?8

            ?9 ???? // exclude?NUL

            10 ???? for ?( int ?i? = ? 1 ;?i? < ? sizeof ?arrShiftTable? / ? sizeof ?( int );?i ++ )
            11 ????
            {
            12 ????????arrShiftTable[i]? =
            ?pLen;
            13 ????}

            14
            15 ???? // exclude?the?last?char?in?pattern

            16 ???? for ?( int ?i? = ? 0 ;?i? < ?pLen? - ? 1 ;?i ++ )
            17 ????
            {
            18 ????????arrShiftTable[pattern[i]]? = ?pLen? - ? 1 ? -
            ?i;
            19 ????}

            20
            21 ???? for ?(currPos? = ?pLen? - ? 1 ;?currPos? < ?tLen;? /* null */
            )
            22 ????
            {
            23 ???????? for ?(pReadPos? = ?pLen? - ? 1 ,?tReadPos? =
            ?currPos;
            24 ????????????pReadPos? >= ? 0 ? && ?pattern[pReadPos]? ==
            ?text[tReadPos];
            25 ????????????pReadPos -- ,?tReadPos --
            )
            26 ???????????? /* null */
            ;
            27

            28 ???????? if ?(pReadPos? < ? 0
            )
            29 ????????
            {
            30 ???????????? return ?tReadPos? + ? 1
            ;
            31 ????????}
            ?
            32 ???????? else

            33 ???????? {
            34 ????????????currPos? +=
            ?arrShiftTable[text[currPos]];
            35 ????????}

            36
            37 ????}
            // outer?for
            38
            39 ???? return ? - 1 ;
            40 }
            算法原理就不細(xì)說(shuō)了,有興趣可以google一下,主要思想就是從模式串的最后一個(gè)字母向前比較。此處需要使用一個(gè)跳轉(zhuǎn)表,以便查詢不匹配時(shí)模式串前進(jìn)的步數(shù)。
            posted on 2006-11-16 18:03 Charles 閱讀(1036) 評(píng)論(1)  編輯 收藏 引用 所屬分類: 面試小算法

            FeedBack:
            # re: 字符串無(wú)回溯BM匹配算法
            2006-11-16 23:05 | 海上冰魂
            汗。完全看不懂:(  回復(fù)  更多評(píng)論
              
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            決定開(kāi)始寫工作日記,記錄一下自己的軌跡...

            常用鏈接

            留言簿(4)

            隨筆分類(70)

            隨筆檔案(71)

            charles推薦訪問(wèn)

            搜索

            •  

            積分與排名

            • 積分 - 50534
            • 排名 - 449

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久99精品免费一区二区| 亚洲国产精品无码久久久不卡| 伊人 久久 精品| 亚洲欧洲久久久精品| 国产精品免费久久久久电影网| 国产精品天天影视久久综合网| 久久精品国产亚洲av麻豆蜜芽| 久久久www免费人成精品| 久久婷婷午色综合夜啪| 亚洲香蕉网久久综合影视| 亚洲国产精品无码久久一线| 久久久久久午夜成人影院| 国产精品美女久久久久久2018| 乱亲女H秽乱长久久久| 久久久久人妻一区精品色| 国产精品美女久久久久网| 国产激情久久久久影院小草 | 久久99精品久久久久久久久久| 亚洲精品乱码久久久久久久久久久久 | 色综合久久中文色婷婷| 国产精品熟女福利久久AV| 性高湖久久久久久久久AAAAA| 伊人久久五月天| 久久99热只有频精品8| 国内精品久久久久久久久| 婷婷久久综合| 久久久老熟女一区二区三区| 国产精品嫩草影院久久| 久久综合久久综合亚洲| 久久精品99久久香蕉国产色戒 | 欧美久久精品一级c片片| 久久精品国产亚洲Aⅴ香蕉| 香蕉久久av一区二区三区| 国产精品99久久久久久董美香| 亚洲精品无码成人片久久| 国内精品久久久久久中文字幕| 久久久亚洲AV波多野结衣| 久久综合伊人77777| 久久r热这里有精品视频| 狠狠精品久久久无码中文字幕| 91久久精品电影|