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

            Jiwu Bu

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              32 隨筆 :: 0 文章 :: 25 評(píng)論 :: 0 Trackbacks
            正確版本:
             1 #include <iostream>
             2 #include <list>
             3 #include <algorithm>
             4 using namespace  std;
             5 
             6 int main(int argc, char* argv[])
             7 {
             8     list<int> MyList;
             9     
            10     for (int i = 0; i < 10; i++)
            11     {
            12         MyList.push_back(i);
            13     }
            14 
            15     list<int>::iterator Itor;
            16 
            17     for ( Itor = MyList.begin(); Itor != MyList.end(); )
            18     {
            19         if ( *Itor == 4 )
            20         {
            21             Itor = MyList.erase(Itor);
            22         }
            23         else
            24         {
            25             Itor++;
            26         }
            27     }
            28 
            29     copy(MyList.begin(), MyList.end(), ostream_iterator<int>(cout, " ") );
            30     cout<<endl;
            31 
            32     return 0;
            33 }

            錯(cuò)誤版本:
             1 #include <iostream>
             2 #include <list>
             3 #include <algorithm>
             4 using namespace  std;
             5 
             6 int main(int argc, char* argv[])
             7 {
             8     list<int> MyList;
             9     
            10     for (int i = 0; i < 10; i++)
            11     {
            12         MyList.push_back(i);
            13     }
            14 
            15     list<int>::iterator Itor;
            16 
            17     for ( Itor = MyList.begin(); Itor != MyList.end(); Itor++)
            18     {
            19         if ( *Itor == 4 )
            20         {
            21             MyList.erase(Itor); //斷鏈,出錯(cuò)地方
            22         }
            23     }
            24 
            25     copy(MyList.begin(), MyList.end(), ostream_iterator<int>(cout, " ") );
            26     cout<<endl;
            27 
            28     return 0;
            29 }


            posted on 2009-07-14 22:33 bujiwu 閱讀(22114) 評(píng)論(2)  編輯 收藏 引用 所屬分類: Note

            評(píng)論

            # re: 從STL中的list刪除元素 2009-07-18 14:53 Alan
            謝謝  回復(fù)  更多評(píng)論
              

            # re: 從STL中的list刪除元素 2014-04-24 23:18 CDD
            學(xué)習(xí)了  回復(fù)  更多評(píng)論
              


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


            久久久久女人精品毛片| 一本色道久久HEZYO无码| 久久综合久久久| 国产精品久久国产精品99盘| 久久久精品午夜免费不卡| 99久久国产免费福利| 亚洲国产综合久久天堂| 国产精品无码久久久久久| 久久精品亚洲男人的天堂| 国产亚洲精久久久久久无码77777| 人妻精品久久无码区| 欧美精品丝袜久久久中文字幕| 久久婷婷五月综合97色一本一本 | 久久久久久久免费视频| 久久午夜无码鲁丝片| 伊人久久大香线蕉AV一区二区| 精品久久久久香蕉网| 99久久免费国产精品特黄| 精品国产91久久久久久久a | 99久久精品国产一区二区三区| 久久久久久综合网天天| 久久亚洲精品无码播放| 久久综合狠狠色综合伊人| 亚洲va久久久噜噜噜久久男同| 久久露脸国产精品| 久久AAAA片一区二区| 秋霞久久国产精品电影院| 久久精品卫校国产小美女| 武侠古典久久婷婷狼人伊人| 国产精品VIDEOSSEX久久发布| jizzjizz国产精品久久| 久久亚洲中文字幕精品有坂深雪| 综合久久精品色| 亚洲日韩欧美一区久久久久我| 久久久久久久亚洲精品| 久久影院午夜理论片无码| 国产精品美女久久久网AV| 99久久精品无码一区二区毛片 | 亚洲国产精品久久久久婷婷软件| 天天躁日日躁狠狠久久 | 99久久精品国产综合一区 |