static void TestMinFallingPath() { var grid = new int[3, 3] { { 1, 2, 3 }, { 4, 1, 1 }, { 7, 8, 9 } }; var gm = new GraphMatrix(grid); Console.WriteLine("Min Falling Path is: " + gm.MinFallingPath()); }
static void Main(string[] args) { #region 图的邻接表的构造 GraphNode[] nodes = new GraphNode[5]; for (int i = 0; i < nodes.Length; i++) { nodes[i] = new GraphNode(i); } nodes[0].AddToNeighbos(nodes[2], nodes[4]); nodes[1].AddToNeighbos(nodes[0], nodes[2]); nodes[2].AddToNeighbos(nodes[3]); nodes[3].AddToNeighbos(nodes[4]); nodes[4].AddToNeighbos(nodes[1]); GraphLinkedList gl = new GraphLinkedList(nodes); #endregion #region 图的邻接矩阵的构造 GraphMatrix gm = new GraphMatrix(5); gm.AddPath(0, 2); gm.AddPath(0, 4); gm.AddPath(1, 0); gm.AddPath(1, 2); gm.AddPath(2, 3); gm.AddPath(3, 4); gm.AddPath(4, 3); #endregion #region 深度优先遍历图(邻接表) //foreach (var item in gl.DFS()) //{ // Console.WriteLine(item.Value); //} #endregion #region 宽度优先遍历图(邻接表) //foreach (var item in gl.BFS()) //{ // Console.WriteLine(item.Value); //} #endregion #region 判断是否有环 //Console.WriteLine(gl.HaveCircleDFS()); //Console.WriteLine(gl.HaveCircleBFS()); #endregion Console.ReadKey(); }
static void TestMatrixGraph() { var grid = new int[5, 5] { { 1, 1, 0, 0, 0 }, { 0, 1, 0, 0, 1 }, { 1, 0, 0, 1, 1 }, { 0, 0, 0, 0, 0 }, { 1, 0, 1, 0, 1 } }; var gm = new GraphMatrix(grid); Console.WriteLine("Number of island is: " + gm.NumberOfIslands()); }
static void TestMaxtricFindUniquePaths() { var grid = new int[3, 3] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 0 } }; var gm = new GraphMatrix(grid); Console.WriteLine("Number of island is: " + gm.NumberOfUniquePathsWithObstacles(new int[2] { 0, 0 }, new int[2] { 2, 2 })); }