vector嵌套vector嵌套pair
vector< vector<pair<int, int> > >的用法
通過簡單的例子來理解vector和vector的嵌套
第一層vector< vector<pair<int, int> > >
第二層 vector<pair<int,int>>
第三層 pair<int ,int>
測試結果
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
分析
輸出
測試結果表明,最外層vector 有4個元素,每一個元素都是一個vector;第二層vector大小也是4,而且內容是點對(pair)。
構造過程
先形成點對(pair),然后把pair放入到內層vector,再把內層vector 放入到外層vector中。
舉例
最小生成樹(MST)prim算法使用到這個寫法,特意記錄一下
總結
以上是生活随笔為你收集整理的vector嵌套vector嵌套pair的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 并查集简单使用
- 下一篇: 最小生成树(MST)