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

            亚洲中文精品久久久久久不卡| 久久久久久久综合日本亚洲 | 人妻精品久久久久中文字幕69| av色综合久久天堂av色综合在| 久久久久免费看成人影片| 国产国产成人精品久久| 久久久久人妻一区精品果冻| 婷婷久久五月天| 国产一区二区精品久久| 四虎国产精品成人免费久久| 亚洲愉拍99热成人精品热久久| 色噜噜狠狠先锋影音久久| 亚洲另类欧美综合久久图片区| 国内精品人妻无码久久久影院| 精品99久久aaa一级毛片| 久久久久国产精品嫩草影院| 日本亚洲色大成网站WWW久久| 久久久久99这里有精品10| 人妻无码中文久久久久专区| 日本福利片国产午夜久久| 久久99热这里只频精品6| 久久精品国产亚洲一区二区| 久久久精品人妻一区二区三区蜜桃 | 久久免费线看线看| 97久久国产综合精品女不卡| 国产精品免费久久| 无码人妻久久久一区二区三区| 激情综合色综合久久综合| 国产精品9999久久久久| 久久久久久免费视频| 久久99久久无码毛片一区二区 | 久久亚洲欧洲国产综合| 精品999久久久久久中文字幕| 7777久久久国产精品消防器材| 国产免费久久精品丫丫| 国产V亚洲V天堂无码久久久| 久久精品国产2020| 亚洲国产精品一区二区三区久久 | 精品久久人妻av中文字幕| 99精品久久精品一区二区| 色婷婷久久久SWAG精品|