我正在尝试弄清楚如何访问顶点边缘的值,以便我可以打印图形。
这是我对addEdge的实现:
void clsGraph::add_edge(clsVertex* source, clsVertex* destination, int id, double weght)
{
clsEdge *a = new clsEdge;
a->ID = id;
a->weight = weght;
a->destination_vertex = destination;
source->edges.push_back(a);
}
这是我的顶点类:
#ifndef CLSVERTEX_HPP
#define CLSVERTEX_HPP
#include <vector>
#include "clsEdge.hpp"
using namespace std; //namespace Rajkarnikar
{
class clsVertex
{
public:
int ID; //integer used to uniquely ID a vertex
vector<clsEdge*> edges; //a vector of pointers to a vertex’s edges
}; //
}
#endif
我有这个命令来添加我的顶点:
void clsGraph::add_vertex(clsVertex* vertex)
{
verticies.push_back(vertex);
}
我正在尝试做的是访问顶点,然后检查它是否有任何边并输出这些边。
谁能帮我解决这个问题?
感谢您的建议:)这是我使用的解决方案...
cout << ID << " " << graphType << endl;
for (int i = 0; i < verticies.size(); i++){
cout << verticies[i]->ID << "->";
for (int j = 0; j < verticies[i]->edges.size(); j++){
cout << verticies[i]->edges[j]->ID << endl;
}