如何从顶点创建图形? [英] How to create graph from vertex?

查看:146
本文介绍了如何从顶点创建图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的问题是如何创建和存储代表这个列表的图表?



例如

 
5
2 4 5
1 3 4
2 4 5
1 2 3 5
1 3 4



<1>连接到2,4,5


<2> - > 1,3,4



等等。

这里有2(相同)表示。



以及我的第二个问题是如何获得该图的所有表示(在这个图像中我显示2,这是相同的)
对于一个顶点列表只存在一个图形represantation?如果更多,如何得到所有这一切?



在图像中它们是相同的,不同的图纸。

解决方案

  5表示多少行
1> 2,4,5
2> 1,3,4
3> 2,4,5
4> 1,2,3,5
5> 1,3,4

(我很傻,所以我需要在记事本中输入) p>

  #include< stdio.h> 

class Cl_Graph;
class Cl_Chain;

class Cl_Vertex
{
friend Cl_Graph;
私人:
Cl_Chain * mp_linkedTo;
Cl_Vertex();
void f_addLink(Cl_Vertex * in_link);
};

Cl_Vertex :: Cl_Vertex()
{
mp_linkedTo = NULL;
}

class Cl_Graph
{
private:
int m_size;
Cl_Vertex * pm_vertexTable;
public:
Cl_Graph(int in_size);
void f_addLink(int in_index,int in_linkWith);
};

Cl_Graph :: Cl_Graph(int in_size)
{
pm_vertexTable = new Cl_Vertex [m_size = in_size];
}

void Cl_Graph :: f_addLink(int in_index,int in_linkWith)
{
if(in_index< m_size&& in_linkWith< m_size)
{
pm_vertexTable [in_index] .f_addLink(pm_vertexTable [in_linkWith]);



int main(int argc,char ** argv)
{
Cl_Graph图(5);
graph.f_addLink(1,2);
graph.f_addLink(1,4);
graph.f_addLink(1,5);
// ...
返回0;
}

你可以从这样的事情开始。你甚至可以输入一个函数来获得一个顶点链作为参数添加到图中,而不是数组,它可以有一串链接链:p祝你好运!


I have a list of connected vertexes.

My question is how to create and store a graph that represents this list?.

For example for

5
2 4 5
1 3 4
2 4 5
1 2 3 5
1 3 4

1 is connected to 2, 4, 5

2 -> 1, 3, 4

and so on..

Here is 2 (the same) representations.

And my second question is how to get all representations of that graph (in this image i showed 2, that are the same) For one list of vertexes exists only one graphical represantation? if more, how to get all of that?

in image they are the same, differente drawings.

解决方案

5 means how many lines
1 > 2, 4, 5
2 > 1, 3, 4
3 > 2, 4, 5
4 > 1, 2, 3, 5
5 > 1, 3, 4

(I am silly so I needed to type this in notepad).

#include <stdio.h>

class Cl_Graph;
class Cl_Chain;

class Cl_Vertex
{
friend Cl_Graph;
private:
    Cl_Chain* mp_linkedTo;
    Cl_Vertex();
    void f_addLink(Cl_Vertex* in_link);
};

Cl_Vertex::Cl_Vertex()
{
    mp_linkedTo= NULL;
}

class Cl_Graph
{
private:
    int m_size;
    Cl_Vertex* pm_vertexTable;
public:
    Cl_Graph(int in_size);
    void f_addLink(int in_index, int in_linkWith);
};

Cl_Graph::Cl_Graph(int in_size)
{
    pm_vertexTable= new Cl_Vertex[m_size= in_size];
}

void Cl_Graph::f_addLink(int in_index, int in_linkWith)
{
    if (in_index< m_size && in_linkWith< m_size)
    {
        pm_vertexTable[in_index].f_addLink(pm_vertexTable[in_linkWith]);
    }
}

int main(int argc, char** argv)
{
    Cl_Graph graph(5);
    graph.f_addLink(1, 2);
    graph.f_addLink(1, 4);
    graph.f_addLink(1, 5);
    // ...
    return 0;
}

You can start with something like this. You can even type a function that would get a chain of vertexes as argument to add to graph, and instead of the array it can have a chain of link chains :p good luck!

这篇关于如何从顶点创建图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆