Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 根据节点的密度填写节点的邻接列表_C#_Graph - Fatal编程技术网

C# 根据节点的密度填写节点的邻接列表

C# 根据节点的密度填写节点的邻接列表,c#,graph,C#,Graph,我有一个Node类型的列表。我想从这个列表中创建一个图,因此我使用邻接列表来实现这个目的。node类型的每个节点都有与其关联的邻接列表。这是我的类节点 我主要创建以下图形: Graph<Node> graph1 = new Graph<Node>(List1); 是否正确?现在是否要格式化输出?你可以这样做 var adjacencylist = nodeSet.Select(x => new KeyValuePair<Node, List<Node

我有一个Node类型的列表。我想从这个列表中创建一个图,因此我使用邻接列表来实现这个目的。node类型的每个节点都有与其关联的邻接列表。这是我的类节点

我主要创建以下图形:

 Graph<Node> graph1 = new Graph<Node>(List1);

是否正确?

现在是否要格式化输出?你可以这样做

var adjacencylist = nodeSet.Select(x => new KeyValuePair<Node, List<Node>>(x, x.Neighbours));

密度定义为邻域长度吗?是的,你可以这么说。密度定义每个节点连接到的节点数。。。。那么,给定节点n的“邻接列表”不就是n个邻居吗?如果我遗漏了什么,请解释一下。我不明白你的意思。我在这里想的是,我想将节点添加到每个节点的“邻居”列表中。但我不知道该怎么做。我应该在从列表创建图形之前还是之后创建图形。@Jashaszun是的,你是对的,我在这里看到的是,假设列表1中有一些节点。现在,列表1中的每个节点都有一些与其关联的密度。假设List1[0]的密度为6,那么在List1[0]的邻接列表中,我想添加6个节点。但是我不确定我应该在哪里实现它。你想如何/在哪里使用它?正如你所描述的,adjacencylist似乎就是neightbors。让我们先忘掉图形,假设类Node本身中有AddNode和AddEdge方法。那么这是正确的吗?
 Graph<Node> graph1 = new Graph<Node>(List1);
foreach (Node node in List1)
        {
            int count = 0, i = 0;
            while (count <= node.Density)
            {
                node.AddNode(List1[i]);
                Node.AddEdge(node, List1[i]);
                count++;
                i++;
            }
        }
var adjacencylist = nodeSet.Select(x => new KeyValuePair<Node, List<Node>>(x, x.Neighbours));