public DFSTest() { AdjacencyList <int> adjacencyList = new AdjacencyList <int>(); ForDFSNode <int> firstHead = new ForDFSNode <int> { Data = 1 }; ForDFSNode <int> secondHead = new ForDFSNode <int> { Data = 2 }; ForDFSNode <int> thirdHead = new ForDFSNode <int> { Data = 3 }; ForDFSNode <int> forthHead = new ForDFSNode <int> { Data = 4 }; adjacencyList.Nodes.AddRange(new List <ForDFSNode <int> > { firstHead, secondHead, thirdHead, forthHead }); adjacencyList.NeighborsList.Add(firstHead, new List <Node <int> > { secondHead, forthHead }); adjacencyList.NeighborsList.Add(secondHead, new List <Node <int> > { firstHead, thirdHead, forthHead }); adjacencyList.NeighborsList.Add(thirdHead, new List <Node <int> > { secondHead, forthHead }); adjacencyList.NeighborsList.Add(forthHead, new List <Node <int> > { firstHead, secondHead, thirdHead }); _dfs = new DFS <int>(adjacencyList); }
private void DoVisit(ForDFSNode <T> node) { node.Color = Base.NodeColor.GRAY; node.StartTime = time; time++; Console.WriteLine("node {0} found in time {1} parent is {2}", node.Data, node.StartTime, node.Parent == null?"null":node.Parent.Data.ToString()); foreach (var item in _list.NeighborsList[node]) { var temp = (ForDFSNode <T>)item; if (temp.Color == Base.NodeColor.WHITE) { temp.Parent = node; DoVisit(temp); } } node.Color = Base.NodeColor.BLACK; node.EndTime = time; time++; Console.WriteLine("node {0} visited in time {1}", node.Data, node.EndTime); }