private static void TestGrapDFSTravesal() { // 0 // / \ // 1 2 // / // 3 UndirectedGraph<int> graph = new UndirectedGraph<int>(); AdjacentListNode<int> node = new AdjacentListNode<int>(0); AdjacentListNode<int> node1 = new AdjacentListNode<int>(1); AdjacentListNode<int> node2 = new AdjacentListNode<int>(2); AdjacentListNode<int> node3 = new AdjacentListNode<int>(3); // Disconnected node AdjacentListNode<int> node4 = new AdjacentListNode<int>(4); // Add immediated neighbors of Node 1 node.Neighbors.Add(node1); node.Neighbors.Add(node2); node1.Neighbors.Add(node); // Add immediate neighbors of node 2 node2.Neighbors.Add(node3); node2.Neighbors.Add(node); node3.Neighbors.Add(node2); List<AdjacentListNode<int>> allNodes = new List<AdjacentListNode<int>>() { node, node1, node3, node2, node4 }; Console.WriteLine("/********** DFS Traversal Adjacent List ****/"); // Traverse all nodes and its vertices graph.DFSAdjacentList(allNodes); Console.WriteLine("/********** DFS Recursion ****/"); // Traverse all nodes using recursion graph.DFSAdjacentListRecursive(allNodes); }