public UndirectedGraphNode CloneGraph(UndirectedGraphNode node) { if (node == null) { return(node); } return(Clone(node)); }
private UndirectedGraphNode Clone(UndirectedGraphNode node) { UndirectedGraphNode destinationNode = null; if (hash.Contains(node.label)) { return((UndirectedGraphNode)hash[node.label]); } destinationNode = new UndirectedGraphNode(node.label); hash.Add(destinationNode.label, destinationNode); foreach (var item in node.neighbors) { destinationNode.neighbors.Add(Clone(item)); } return(destinationNode); }