无向图求所有路径
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5
{
class Program
{
static void Main(string[] args)
{
/* 定义节点关系 */
int[][] nodeRalation = new int[][]
{
new int[]{1}, //0
new int[]{0,5,2,3},//1
new int[]{1,4}, //2
new int[]{1,4}, //3
new int[]{2,3,5}, //4
new int[]{1,4} //5
};
/* 定义节点数组 */
Node[] node = new Node[nodeRalation.Length];
for(int i=0;i < nodeRalation.Length; i++)
{
node[i] = new Node();
node[i].Name = "node" + i;
}
/* 定义与节点相关联的节点集合 */
for(int i=0;i)
{
List List = new List();
for(int j=0;j)
{
List.Add(node[nodeRalation[i][j]]);
}
node[i].RelationNodes = List;
List = null; //释放内存
}
/* 开始搜索所有路径 */
GetPaths(node[0], null, node[0], node[4]);
Console.ReadKey();
}
/* 临时保存路径节点的栈 */
public static Stack stack = new Stack();
/* 存储路径的集合 */
public static List[]>[i].length;>;>
参考:https://blog.csdn.net/hcx25909/article/details/8043107
Original: https://www.cnblogs.com/kissdodog/p/15009598.html
Author: 逆心
Title: 无向图求所有路径C#版
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/552309/
转载文章受原作者版权保护。转载请注明原作者出处!