vector嵌套vector嵌套pair
vector< vector<pair<int, int> > >的用法
通過(guò)簡(jiǎn)單的例子來(lái)理解vector和vector的嵌套
第一層vector< vector<pair<int, int> > >
第二層 vector<pair<int,int>>
第三層 pair<int ,int>
測(cè)試結(jié)果
size of vec: 4
vec一層
the value is: 0 0
the value is: 0 1
the value is: 0 2
the value is: 0 3
vec一層
the value is: 1 0
the value is: 1 1
the value is: 1 2
the value is: 1 3
vec一層
the value is: 2 0
the value is: 2 1
the value is: 2 2
the value is: 2 3
vec一層
the value is: 3 0
the value is: 3 1
the value is: 3 2
the value is: 3 3
分析
輸出
測(cè)試結(jié)果表明,最外層vector 有4個(gè)元素,每一個(gè)元素都是一個(gè)vector;第二層vector大小也是4,而且內(nèi)容是點(diǎn)對(duì)(pair)。
構(gòu)造過(guò)程
先形成點(diǎn)對(duì)(pair),然后把pair放入到內(nèi)層vector,再把內(nèi)層vector 放入到外層vector中。
舉例
最小生成樹(shù)(MST)prim算法使用到這個(gè)寫(xiě)法,特意記錄一下
總結(jié)
以上是生活随笔為你收集整理的vector嵌套vector嵌套pair的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 并查集简单使用
- 下一篇: 最小生成树(MST)