• <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  回復  更多評論
              

            91精品国产综合久久四虎久久无码一级| 99久久777色| 婷婷久久综合九色综合绿巨人| 开心久久婷婷综合中文字幕| 久久天天躁狠狠躁夜夜avapp| 久久99精品国产麻豆| 久久www免费人成精品香蕉| 久久笫一福利免费导航 | 99久久精品这里只有精品| 久久久久综合中文字幕| 精品久久8x国产免费观看| 久久婷婷五月综合97色直播| 久久夜色精品国产网站| 无码任你躁久久久久久| 91久久国产视频| MM131亚洲国产美女久久| 思思久久99热免费精品6| 久久亚洲国产午夜精品理论片| 中文精品久久久久人妻不卡| 久久九九久精品国产| 99久久www免费人成精品| 精品综合久久久久久888蜜芽| 中文字幕精品久久| 亚洲欧洲中文日韩久久AV乱码| 国产精品久久久久久| 久久久久久夜精品精品免费啦| 欧洲国产伦久久久久久久 | 久久人爽人人爽人人片AV| 伊人久久精品影院| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 精品国产福利久久久| 久久精品人人做人人爽电影蜜月| 三级片免费观看久久| 久久精品女人天堂AV麻| 久久午夜福利电影| 久久亚洲国产成人精品无码区| 亚洲国产成人久久综合碰碰动漫3d | 狠狠色丁香久久婷婷综合_中| 无码精品久久一区二区三区| 久久不见久久见免费影院www日本| 91精品国产乱码久久久久久 |