STL 常用容器

來源:互聯網
上載者:User

標籤:style   blog   color   for   div   log   sp   on   c   

 1     //動態數組 2     vector<int> theVector; 3     theVector.push_back(1); 4     theVector.push_back(2); 5     theVector.push_back(3); 6     theVector.pop_back(); 7     vector<int>::iterator itVector; 8     cout << "vector" << endl; 9     for(itVector = theVector.begin(); itVector != theVector.end(); itVector++)10     {11         cout << *itVector << endl;12     }13 14     //雙向鏈表15     list<int> theList;16     theList.push_back(1);17     theList.push_front(2);18     list<int>::iterator itList;19     cout << "list" << endl;20     for(itList = theList.begin(); itList != theList.end(); itList++)21     {22         cout << *itList << endl;23     }24 25     //棧26     stack<int> theStack;27     theStack.push(1);28     theStack.push(2);29     theStack.push(3);30     theStack.pop();31     cout << "stack" << endl;32     while(!theStack.empty())33     {34         cout << theStack.top() << endl;35         theStack.pop();36     }37 38     //隊列39     queue<int> theQueue;40     theQueue.push(1);41     theQueue.push(2);42     theQueue.push(3);43     theQueue.pop();44     cout << "queue" << endl;45     while(!theQueue.empty())46     {47         cout << theQueue.front() << endl;48         theQueue.pop();49     }50 51     //紅/黑樹狀結構52     map<int, string, less<int> > theMap;//模版最後位置加空格53     theMap.insert(map<int, string, less<int> >::value_type(0,"Zero"));54     theMap.insert(map<int, string, less<int> >::value_type(1,"One"));55     theMap.insert(map<int, string, less<int> >::value_type(2,"Two"));56     map<int, string, less<int> >::iterator itMap;57     cout << "map" << endl;58     for(itMap = theMap.begin(); itMap != theMap.end(); itMap++)59     {60         cout << (*itMap).second << endl;61     }

 

STL 常用容器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.