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

            大規(guī)模高性能網(wǎng)絡(luò)服務(wù)器編程 大型游戲服務(wù)器編程


            大規(guī)模高性能網(wǎng)絡(luò)服務(wù)器編程 大型游戲服務(wù)器編程 完成端口模型 TCP UDP P2P 網(wǎng)絡(luò)編程

                       C++博客 | 首頁 | 發(fā)新隨筆 | 發(fā)新文章 | 聯(lián)系 | 聚合 | 管理

                          

            STL容器使用之二:deque


            本文原創(chuàng)發(fā)表地址為:http://m.shnenglu.com/kusamba/archive/2010/09/17/126895.html,轉(zhuǎn)載請保留原鏈接,謝謝!


            deque的數(shù)據(jù)結(jié)構(gòu)示意圖:

            技術(shù)要點(diǎn):
            隨機(jī)訪問每個元素,所需要的時間為常量。
            在開頭和末尾增加元素所需時間與元素數(shù)目無關(guān),在中間增加或刪除元素所需時間隨元素數(shù)目呈線性變化。
            可動態(tài)增加或減少元素,內(nèi)存管理自動完成,不提供用于內(nèi)存管理的成員函數(shù)。


            參考代碼:
             1 /************************************************************************
             2 * deque:
             3 *    1, 分塊分配空間,非順序存儲,隨機(jī)訪問是通過復(fù)雜的iterator實(shí)現(xiàn)
             4 *    2, 在前后插入數(shù)據(jù)時間復(fù)雜度為O(1)
             5 *    3, 迭代器失效:
             6 *       If an element is inserted into an empty sequence, or if an element is 
             7        erased to leave an empty sequence, then iterators earlier returned 
             8        by begin and end become invalid.
             9 
            10        If an element is inserted at the first position of the deque, 
            11        then all iterators, but no references, that designate existing 
            12        elements become invalid.
            13 
            14        If an element is inserted at the end of the deque, then end and all 
            15        iterators, but no references, that designate existing elements become invalid.
            16 
            17        If an element is erased at the front of the deque, only that iterator 
            18        and references to the erased element become invalid.
            19 
            20        If the last element is erased from the end of the deque, only that 
            21        iterator to the final element and references to the erased element become invalid.
            22 
            23        Otherwise, inserting or erasing an element invalidates all iterators and references.
            24 
            25 *    by Kusamba@126.com    http://m.shnenglu.com/kusamba
            26 */
            27 void deque_test()
            28 {
            29     deque<int> dqInt;
            30 
            31     int nSize = dqInt.size();
            32     int nMaxSiz = dqInt.max_size();
            33 
            34     dqInt.resize(100);
            35     dqInt.resize(102);
            36     
            37     /**
            38     * push_back
            39     */
            40     for (int i = 0; i < 10++i)
            41     {
            42         dqInt[i] = i + 1;
            43     }
            44     for (int i = 0; i < 10++i)
            45     {
            46         dqInt.push_back(i + 11);
            47     }
            48 
            49     /**
            50     * insert
            51     */
            52     for (deque<int>::iterator it = dqInt.begin(); it != dqInt.end();)
            53     {
            54         if (*it % 3 == 0//在3的倍數(shù)的元素后面插入100
            55         {
            56             it = dqInt.insert(it + 1100);
            57         } 
            58         else
            59         {
            60             ++it;
            61         }
            62     }
            63 
            64     /**
            65     * erase
            66     */
            67     for (deque<int>::iterator it = dqInt.begin(); it != dqInt.end();)
            68     {
            69         if (*it == 4)
            70         {
            71             it = dqInt.erase(it);
            72         } 
            73         else
            74         {
            75             ++it;
            76         }
            77     }
            78 
            79     /**
            80     * traverse
            81     */
            82     printf("print deque: ");
            83     for (int i = 0; i < dqInt.size(); ++i)
            84     {
            85         printf("%d ", dqInt[i]);
            86     }
            87     printf("\n");
            88 
            89     /**
            90     * pop
            91     */
            92     while (!dqInt.empty())
            93     {
            94         int nItemVal = dqInt.front();
            95         dqInt.pop_front();
            96     }
            97 }


            posted on 2010-09-17 17:19 iKusamba 閱讀(1690) 評論(0)  編輯 收藏 引用 所屬分類: C++技術(shù)

            公告

            導(dǎo)航

            隨筆分類

            最新隨筆

            最新評論

            閱讀排行榜

            亚洲国产精品综合久久网络 | 国产高潮久久免费观看| 97久久精品人妻人人搡人人玩| 亚洲国产精品无码久久98| 精品综合久久久久久888蜜芽| 91超碰碰碰碰久久久久久综合| 国内精品久久久久久久久电影网| 中文字幕成人精品久久不卡 | 亚洲精品国精品久久99热| 亚洲AV日韩AV永久无码久久| 国产日韩久久免费影院| 亚洲va久久久噜噜噜久久狠狠| 国产日韩欧美久久| 久久精品国产亚洲AV高清热| 伊人久久大香线蕉综合网站| 国产L精品国产亚洲区久久| 久久男人Av资源网站无码软件| 欧美久久一级内射wwwwww.| 国产精品久久久久久搜索| 久久偷看各类wc女厕嘘嘘| 久久久久亚洲精品日久生情| 国内精品久久久久国产盗摄| 久久综合狠狠综合久久综合88| 久久中文精品无码中文字幕| A级毛片无码久久精品免费| 精品久久久久久亚洲精品| 麻豆AV一区二区三区久久| 日韩精品久久无码人妻中文字幕| 亚洲国产精品狼友中文久久久 | 国产福利电影一区二区三区久久老子无码午夜伦不 | 无码人妻久久一区二区三区免费 | 亚洲国产成人精品无码久久久久久综合| 久久综合狠狠综合久久| 热re99久久精品国99热| 97精品依人久久久大香线蕉97| 一级做a爰片久久毛片毛片| 亚洲色欲久久久久综合网| 国内精品伊人久久久影院 | 青青草国产97免久久费观看| 热综合一本伊人久久精品| 久久亚洲精品无码VA大香大香|