struct Edge int src tgt; float weight;;stdvectorEdge resulta;从最小生成树resulta中删除p00和p0的edge的c++代码
下面是一个示例的C++代码,用于从最小生成树resulta中删除src为p00和tgt为p0的边:
#include <vector>
struct Edge
{
int src, tgt;
float weight;
};
std::vector<Edge> resulta;
void removeEdge(int src, int tgt)
{
for (auto it = resulta.begin(); it != resulta.end(); ++it)
{
if (it->src == src && it->tgt == tgt)
{
resulta.erase(it);
break;
}
}
}
int main()
{
// 假设 p00 的 src 为 1,tgt 为 2
// 假设 p0 的 src 为 3,tgt 为 4
removeEdge(1, 2);
removeEdge(3, 4);
return 0;
}
请注意,上述代码只删除了第一个匹配的边。如果需要删除所有匹配的边,可以使用一个循环来遍历并删除所有匹配的边
原文地址: http://www.cveoy.top/t/topic/iS7I 著作权归作者所有。请勿转载和采集!