STL CSB 11.10
生活随笔
收集整理的這篇文章主要介紹了
STL CSB 11.10
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
QUEUE
FIFO
#include <queue> queue<int>qu;// queue<元素類型>隊列名 qu.size();//隊列大小 qu.empty();//隊列是否為空,返回值為bool型 qu.push();//向隊列中存元素 /* qu.push(4); qu.push(133); qu.push(23); 此時 qu.size()為3 */ qu.front();//隊頭元素的值 qu.back();//隊尾元素的值 qu.pop();//隊頭元素出隊 /***********WRITTEN BY LLL***************/ /* while(!qu.empty()) {cout<<q.front()<<" ";q.pop(); } */STACK
FILO(first in last out)
#include<stack> stack<int>st;//棧的聲明 st.size(); st.empty(); st.top(); /**********************WRITTEN BY LLL********************/ /*后續手寫遍歷*/VECTOR//向量
可變大小的數組
可采用下標對vector的元素進行訪問;
MAP//映射
提供1V1的映射
map<int,string>mp; mp.insert(make_pair<int,string>(1,"student_one")); mp["hhh"]=5; int t=mp.size(); mp["heheda"]=17; map<string,int>::iterator iter; for(iter=mp.begin();iter!=mp.end();iter++){cout<<iter->first<<" "<<iter->second<<endl;//按照字典序排序 } //用下標覆蓋?? cout<<mp.count("heheda")<<endl;//結果為1,那heheda出現過了1次。即heheda出現的次數 iter=mp.find("hhh"); mp.erase(iter); mp.clear();PAIR
pair<int,int>k; k.first=1; k.second=2;SET//集合
已經從小到大排列好了的集合(互斥性)
set<int>st;//不能用下標,只能用迭代器訪問 begin(); end(); clear(); empty(); size(); /*需要迭代器承載or做參數 find(); erase(); */ //用insert來插入 st.insert(data); set<int>::iterator iter; //遍歷 for(iter=st.begin();iter!=st.end();iter++){cout<<*iter<<endl; } cout<<st.size(); iter=st.find(10); st.erase(iter); count();//count返回出現次數,set只能是否出現過,multiset是次數 /*課后了解 結構體的時候實現map排的方式*/雙端隊列&優先隊列
dequeue<int> dq; dp.front_push(); dp.back_push(); priority_queue<int>q; //實時操作,nlgn q.top();總結
以上是生活随笔為你收集整理的STL CSB 11.10的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Pacman
- 下一篇: logutils java_【java】