• <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++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              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[])
            {
                
            //創(chuàng)建一個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;
                    }
                }

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

                
            //所有操作均已經(jīng)結束
                cout << "------------------------------------------------" << endl << "操作:所有操作均已經(jīng)結束" << endl;
                cout 
            << "------------------------------------------------" << endl;

                
            return 0;
            }

            posted on 2011-07-04 20:30 Jacc.Kim 閱讀(9609) 評論(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久久成人国产精品免费 | 久久99精品久久久久久齐齐| 精品综合久久久久久88小说| 热99RE久久精品这里都是精品免费 | 久久只这里是精品66| 日本精品久久久久中文字幕| 久久亚洲国产最新网站| 69国产成人综合久久精品| 欧美亚洲国产精品久久久久| 亚洲国产精品久久久久婷婷软件 | 久久久久亚洲AV无码去区首| 久久久久国产精品熟女影院 | 久久久久久极精品久久久| 久久久久久亚洲AV无码专区| 国产高潮国产高潮久久久91 | 亚洲国产天堂久久综合网站| 午夜精品久久久久久久| 国产色综合久久无码有码| 亚洲性久久久影院| 久久精品无码一区二区三区日韩| 久久综合久久美利坚合众国| 麻豆精品久久久一区二区| 久久精品无码专区免费青青| 亚洲欧美伊人久久综合一区二区| 久久精品无码免费不卡| 精品久久久久中文字幕一区| 国产精品久久久99| 久久国产一片免费观看| 狠狠色丁香婷婷综合久久来来去| 免费观看久久精彩视频| 久久夜色tv网站| 久久国产成人| 中文字幕精品久久| 久久99精品久久久大学生| 精品久久久久中文字幕日本| 成人资源影音先锋久久资源网| 久久久久亚洲精品无码蜜桃| 国产精品国色综合久久| 久久精品国产精品青草app| 久久免费观看视频|