[英]How to access the data of the edges of the vertex in graph?
我試圖弄清楚如何訪問頂點邊緣的值,以便可以打印圖形。
這是我的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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.