日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

笔记(2015-07-24)

發(fā)布時間:2023/12/9 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 笔记(2015-07-24) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

STL方面的筆記

以下為vector queue map set stack的基本用法?
可編譯結(jié)合注釋查看

?

?

1 #include <vector> 2 #include <iostream> 3 #include <queue> 4 #include <map> 5 #include <set> 6 #include <stack> 7 using namespace std; 8 9 #define REP(n) for(int o=0;o<n;o++) 10 11 int main(){ 12 13 cout<<"vector功能"<<endl; 14 vector<int> vec;//聲明名稱為vec的整數(shù)型向量 15 vector<int>::iterator it_vec;//迭代器 16 vec.clear();//清空 17 cout<<"插入數(shù)據(jù)"<<endl; 18 vec.push_back(1);//在末尾插入 19 vec.push_back(3); 20 it_vec=vec.end();//指向vec的末尾 21 it_vec--;//向前移動一位(既1和3的中間) 22 vec.insert(it_vec,2);//在此處插入2 23 REP(vec.size())cout<<vec[o]<<endl;//訪問數(shù)據(jù) 24 cout<<"清除第一個數(shù)據(jù)后輸出"<<endl; 25 vec.erase(vec.begin()); 26 it_vec=vec.begin(); 27 REP(vec.size()){ 28 cout<<*it_vec<<endl;//訪問數(shù)據(jù) 29 it_vec++;//向后一位 30 } 31 cout<<"#####################################"<<endl<<endl; 32 33 34 cout<<"map功能"<<endl; 35 map<string,vector<int> > m;//聲明 key的類型為string value類型為int型vector 的 映射m 36 map<string,vector<int> >::iterator it_map;//迭代器 37 cout<<"插入數(shù)據(jù)"<<endl; 38 m.insert(pair<string,vector<int> >("aaa",vec)); 39 it_map=m.find("aaa");//或者指定key的位置(迭代器) 40 cout<<"key:"<<it_map->first<<endl; 41 cout<<"value:"<<endl; 42 REP(vec.size())cout<<" "<<vec[o]<<endl; 43 cout<<"查找一個不存在的數(shù)據(jù) find()會返回map的末尾"<<endl; 44 it_map=m.find("Niconiconi~"); 45 if(it_map==m.end())cout<<"No Niconiconi~"<<endl; 46 cout<<"#####################################"<<endl<<endl; 47 48 cout<<"set功能"<<endl; 49 set<int> s;//聲明一個整數(shù)型集合 50 set<int>::iterator it_set;//迭代器 51 cout<<"倒敘插入數(shù)據(jù)并且有重復(fù)的4"<<endl; 52 s.insert(5); 53 s.insert(4); 54 s.insert(4); 55 s.insert(2); 56 s.insert(1); 57 it_set=s.begin(); 58 while(it_set!=s.end()){ 59 cout<<*it_set<<endl; 60 it_set++; 61 } 62 cout<<"輸出時4自動保留一個,并且數(shù)據(jù)由小到大輸出"<<endl; 63 cout<<"#####################################"<<endl<<endl; 64 65 66 67 cout<<"queue功能"<<endl; 68 queue<string> q;//聲明一個字符串型隊列 q 69 cout<<"按順序插入"<<endl; 70 q.push("L"); 71 q.push("O"); 72 q.push("V"); 73 q.push("E"); 74 q.push("L"); 75 q.push("I"); 76 q.push("V"); 77 q.push("E"); 78 q.push("!"); 79 while(!q.empty()){ 80 cout<<q.front(); 81 q.pop(); 82 } 83 cout<<endl; 84 cout<<"先入隊的先出來"<<endl; 85 cout<<"#################################"<<endl<<endl; 86 87 88 89 cout<<"priority_queue功能"<<endl; 90 priority_queue<string> pq;//聲明priority_queue一個字符串型優(yōu)先隊列 91 cout<<"亂序插入具有可比較大小的數(shù)據(jù)"<<endl; 92 pq.push("B"); 93 pq.push("A"); 94 pq.push("C"); 95 while(!pq.empty()){ 96 cout<<pq.top(); 97 pq.pop(); 98 } 99 cout<<endl; 100 cout<<"權(quán)值大的先出來"<<endl; 101 cout<<"###############################"<<endl<<endl; 102 103 cout<<"stack功能"<<endl; 104 stack<string> sta;//聲明一個字符串類型的棧 105 cout<<"倒序插入數(shù)據(jù)"<<endl; 106 sta.push("+"); 107 sta.push("+"); 108 sta.push("C"); 109 while(!sta.empty()){ 110 cout<<sta.top(); 111 sta.pop(); 112 } 113 cout<<endl; 114 cout<<"先進(jìn)入的后出來"<<endl; 115 return 0; 116 }

?

編譯結(jié)果:

vector功能?
插入數(shù)據(jù)?
1?
2?
3?
清除第一個數(shù)據(jù)后輸出?
2?
3

#

map功能?
插入數(shù)據(jù)?
key:aaa?
value:?
2?
3?
查找一個不存在的數(shù)據(jù) find()會返回map的末尾?
No Niconiconi~

#

set功能?
倒敘插入數(shù)據(jù)并且有重復(fù)的4?
1?
2?
4?
5?
輸出時4自動保留一個,并且數(shù)據(jù)由小到大輸出

#

queue功能?
按順序插入?
LOVELIVE!?
先入隊的先出來

#

priority_queue功能?
亂序插入具有可比較大小的數(shù)據(jù)?
CBA?
權(quán)值大的先出來

#

stack功能?
倒序插入數(shù)據(jù)?
C++?
先進(jìn)入的后出來

轉(zhuǎn)載于:https://www.cnblogs.com/ohyee/p/4680705.html

總結(jié)

以上是生活随笔為你收集整理的笔记(2015-07-24)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。