我有代码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
答案 0 :(得分:0)
您的main
以int v, e;
开头。因此,对v
的引用会看到int
而不是vector
。
(旁白:那些宏。不要这样做。真的。它们阻碍而不是帮助可读性,并且有各种各样的缺点。)