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

            大規模高性能網絡服務器編程 大型游戲服務器編程


            大規模高性能網絡服務器編程 大型游戲服務器編程 完成端口模型 TCP UDP P2P 網絡編程

                       C++博客 | 首頁 | 發新隨筆 | 發新文章 | 聯系 | 聚合 | 管理

                          

            STL容器使用之二:deque


            本文原創發表地址為:http://www.shnenglu.com/kusamba/archive/2010/09/17/126895.html,轉載請保留原鏈接,謝謝!


            deque的數據結構示意圖:

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


            參考代碼:
             1 /************************************************************************
             2 * deque:
             3 *    1, 分塊分配空間,非順序存儲,隨機訪問是通過復雜的iterator實現
             4 *    2, 在前后插入數據時間復雜度為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://www.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的倍數的元素后面插入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 閱讀(1681) 評論(0)  編輯 收藏 引用 所屬分類: C++技術

            公告

            導航

            隨筆分類

            最新隨筆

            最新評論

            閱讀排行榜

            欧美激情精品久久久久久久九九九| 色综合久久中文字幕无码| 久久亚洲国产中v天仙www| 91精品免费久久久久久久久| 久久亚洲2019中文字幕| 亚洲精品乱码久久久久久按摩| 久久国产一区二区| 久久综合色之久久综合| 久久亚洲国产成人精品性色| 国产精品久久久久久久久免费| 久久精品夜色噜噜亚洲A∨| 久久中文字幕人妻丝袜| 成人a毛片久久免费播放| 亚洲精品无码久久千人斩| 久久99久久无码毛片一区二区| 日日噜噜夜夜狠狠久久丁香五月| 国产成人久久精品二区三区| 亚洲国产精品无码久久一区二区 | 国产福利电影一区二区三区久久久久成人精品综合 | 久久96国产精品久久久| 亚洲欧美日韩精品久久亚洲区 | 香蕉久久一区二区不卡无毒影院 | 中文字幕久久亚洲一区| 免费国产99久久久香蕉| 久久精品人人做人人爽97 | 中文字幕无码av激情不卡久久| www.久久热| 久久婷婷成人综合色综合| 久久国产亚洲精品| 久久伊人五月天论坛| 久久久久18| 久久精品国产黑森林| 国产免费久久精品丫丫| 免费观看久久精彩视频| 久久亚洲国产精品一区二区| 日本久久久久亚洲中字幕| 精品久久人人爽天天玩人人妻| 久久婷婷是五月综合色狠狠| 久久久久久曰本AV免费免费| 久久综合一区二区无码| 国内精品伊人久久久久妇|