【问题标题】:how to make a graph data structure from data structures for nodes and arcs?如何从节点和弧的数据结构中制作图形数据结构?
【发布时间】:2013-05-01 08:22:02
【问题描述】:

我已经制作了以下节点和弧结构:

struct arc
{
int length;
string start;
string end;

    arc(int k,string s,string e)
    {
    this->length = k;
    this->start = s;
    this->end = e;
    }
};

struct node
{
string name;
double x;
double y;
vector<arc> link;

node(string n,double xx,double yy)
    {
    this->name = n;
    this->x = xx;
    this->y = yy;
    }
};

现在我想创建一个图形数据结构,以便能够在其上实现 Kruskal 算法。 我无法理解如何利用这两个结构。 每个节点都存储其名称和坐标以及有关往返于它的弧的信息。 所以我有一个节点集群,但我如何将所有东西链接在一起。这里没有根节点。我应该在我的图表类中添加什么? 我已经搜索了邻接列表和矩阵,但无法理解如何将我的想法与它们联系起来?请解释一下

【问题讨论】:

    标签: graph nodes kruskals-algorithm


    【解决方案1】:

    您需要定义一个标准来比较两条弧并确定哪一条“更小”。

    给定两个节点的坐标,知道如何比较它们。
    根据您的标准订购您的弧线。
    从一个包含所有节点但没有弧的空图开始。
    使用 DisjointSet 结构来维护有关连接组件的信息(以避免循环)
    将弧线从小到大添加到图表中,如果循环,则忽略弧线。

    Kruskal 算法:http://en.wikipedia.org/wiki/Kruskal's_algorithm

    不相交集:http://en.wikipedia.org/wiki/Disjoint-set_data_structure

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-13
      • 2018-03-05
      • 2011-05-18
      • 1970-01-01
      • 2010-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多