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

            積木

            No sub title

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              140 Posts :: 1 Stories :: 11 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(1)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            List容器用法操作實例


            // Test_20110513_1756.cpp : Defines the entry point for the console application.
            //

            //////////////////////////////////////////////////////////////////////////
            //* list容器測試
            //////////////////////////////////////////////////////////////////////////

            #include 
            "stdafx.h"

            #include 
            <list>
            #include 
            <iostream>
            using namespace std;

            typedef list
            <int> LISTINT;

            int _tmain(int argc, _TCHAR* argv[])
            {
                
            //創建一個list容器
                LISTINT lInt;

                
            //在list容器的末尾,添加元素
                cout << "------------------------------------------------" << endl << "操作:從后面添加元素" << endl;
                
            for (LISTINT::value_type iValCount = 1; iValCount != 11; iValCount++)
                    lInt.push_back(iValCount);
                
            for (LISTINT::iterator iter = lInt.begin(); iter != lInt.end(); iter++)
                    cout 
            << *iter << endl;

                
            //在list容器的頭部,添加元素
                cout << "------------------------------------------------" << endl << "操作:從前面添加元素" << endl;
                
            for (LISTINT::value_type iValCount = 11; iValCount != 21; iValCount++)
                    lInt.push_front(iValCount);
                
            for (LISTINT::iterator iter = lInt.begin(); iter != lInt.end(); iter++)
                    cout 
            << *iter << endl;

                
            //取出最后一個元素
                cout << "------------------------------------------------" << endl << "操作:取出最后一個元素" << endl;
                cout 
            << lInt.back() << endl;

                
            //取出最前一個元素
                cout << "------------------------------------------------" << endl << "操作:取出最前一個元素" << endl;
                cout 
            << lInt.front() << endl;

                
            //從后向前顯示list中的元素(注意:迭代器,不可以同名,雖然在不同的作用域下)
                cout << "------------------------------------------------" << endl << "操作:從后向向前顯示list中的元素" << endl;
                
            for (LISTINT::reverse_iterator iter2 = lInt.rbegin(); iter2 != lInt.rend(); iter2++)
                    cout 
            << *iter2 << endl;

                
            //刪除一個元素
                cout << "------------------------------------------------" << endl << "操作:刪除最后一個元素" << endl;
                
            if (lInt.size() > 0)
                {
                    LISTINT::iterator delIter 
            = lInt.end();
                    delIter
            --;
                    cout 
            << *delIter << endl;
                    lInt.erase(delIter);
                    
            if (lInt.size() > 0)
                    {
                        delIter 
            = lInt.end();
                        delIter
            --;
                        cout 
            << *delIter << endl;
                    }
                }

                
            //清空元素(并輸入所有元素內容----正常輸出為空。因為被清空了)
                cout << "------------------------------------------------" << endl << "操作:清空所有元素(并輸入所有元素內容----正常輸出為空。因為被清空了)" << endl;
                lInt.clear();
                
            for (LISTINT::iterator iter3 = lInt.begin(); iter3 != lInt.end(); iter3++)
                cout 
            << *iter3 << endl;

                
            //所有操作均已經結束
                cout << "------------------------------------------------" << endl << "操作:所有操作均已經結束" << endl;
                cout 
            << "------------------------------------------------" << endl;

                
            return 0;
            }

            posted on 2011-07-04 20:30 Jacc.Kim 閱讀(9597) 評論(2)  編輯 收藏 引用 所屬分類: VC / C++

            Feedback

            # re: C++List容器用法操作實例 2016-05-03 11:45 dfd
            sdfs   回復  更多評論
              

            # re: C++List容器用法操作實例 2016-05-03 11:47 "><script>alert(1)</script><
            hehe  回復  更多評論
              

            久久精品国产99国产精品| 久久久亚洲AV波多野结衣| av无码久久久久久不卡网站 | 一本大道久久香蕉成人网| 亚洲国产综合久久天堂| 亚洲国产精品高清久久久| 久久99热狠狠色精品一区| 久久久久人妻精品一区三寸蜜桃| 亚洲国产成人乱码精品女人久久久不卡 | 精品久久久久久无码不卡| 久久99中文字幕久久| 久久大香萑太香蕉av| 久久精品国内一区二区三区| 亚洲欧洲精品成人久久奇米网| 国产精品久久影院| 国内精品久久久久影院亚洲| 青青青伊人色综合久久| 97久久国产露脸精品国产| 久久综合伊人77777麻豆| 99久久精品这里只有精品| 久久人人爽人人爽人人片AV不 | 国产成人精品综合久久久久| 久久亚洲精品无码观看不卡| 999久久久免费国产精品播放| 久久精品无码专区免费东京热 | A级毛片无码久久精品免费| 99久久国产综合精品网成人影院| 97久久国产综合精品女不卡| 亚洲а∨天堂久久精品| 久久久精品人妻无码专区不卡| 国产V亚洲V天堂无码久久久| 亚洲精品tv久久久久久久久| 中文精品久久久久人妻不卡| 亚洲精品无码专区久久同性男| 久久婷婷五月综合色99啪ak| 久久久久女教师免费一区| 美女久久久久久| 久久成人小视频| 久久99精品久久久久久hb无码| 久久久国产乱子伦精品作者| 成人国内精品久久久久一区|