• <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)結(jié)束
                cout << "------------------------------------------------" << endl << "操作:所有操作均已經(jīng)結(jié)束" << endl;
                cout 
            << "------------------------------------------------" << endl;

                
            return 0;
            }

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

            Feedback

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

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

            久久婷婷五月综合97色| 伊人久久无码中文字幕| 久久精品中文闷骚内射| 久久国产精品99久久久久久老狼| 丰满少妇高潮惨叫久久久| 国产成人精品久久亚洲高清不卡| 亚洲成av人片不卡无码久久| 色欲久久久天天天综合网精品| 久久无码AV中文出轨人妻| 人妻丰满AV无码久久不卡| 国产精品久久久久久搜索| 久久成人国产精品免费软件| 国内精品伊人久久久久网站| 久久精品国产福利国产秒| 久久亚洲天堂| 久久精品国产精品国产精品污 | 久久人与动人物a级毛片| 久久免费精品视频| 新狼窝色AV性久久久久久| 国产成人精品久久一区二区三区av | 无码国内精品久久人妻麻豆按摩| 成人午夜精品久久久久久久小说| 国产精品久久新婚兰兰 | 久久午夜无码鲁丝片秋霞| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 国产精品久久久久久搜索| 欧美精品国产综合久久| 免费精品99久久国产综合精品| 香蕉久久av一区二区三区| 国内精品伊人久久久久777| 免费一级欧美大片久久网 | 狠狠色婷婷久久一区二区| 久久综合久久鬼色| 国内精品欧美久久精品| 国内精品久久久久久中文字幕| 99久久精品国产综合一区| 伊人久久综在合线亚洲2019 | 久久性精品| 伊人久久亚洲综合影院| 2021国产精品午夜久久| 久久久久久极精品久久久|