使用矢量与对
Use Vector with Pair
我有代码 kruskal 算法 (MST) 并使用这样的对向量
vector<pair<int,pair<int,int> > > v;
我想像这样添加 wight 并使源、目标对
v.push_back(make_pair(wight,make_pair(src,des)));
然后
sort(v.begin(),v.end());
因为它首先根据 x 坐标排序,然后根据 y 坐标排序
它会出现错误
error: request for member ‘push_back’ in ‘v’, which is of non-class type ‘int’
v.push_back(MK(wt,MK(x,y)));
^
error: request for member ‘begin’ in ‘v’, which is of non-class type ‘int’
sort(v.begin(),v.end());
^
error: request for member ‘end’ in ‘v’, which is of non-class type ‘int’
sort(v.begin(),v.end());
^
我正在学习如何使用 c++ STL,并且厌倦了调试它。那么如何推送对并对此向量进行排序呢?
我的代码链接。https://ideone.com/obEhP0
您的main
以 int v, e;
开头。所以参考v
看到的是int
而不是你的vector
.
(旁白:那些宏。别这样。真。它们阻碍而不是帮助可读性,并且有各种缺点。
相关文章:
- 没有找到相关文章