Ejemplo n.º 1
0
        public UndirectedGraphNode CloneGraph(UndirectedGraphNode node)
        {
            if (node == null)
            {
                return(node);
            }

            return(Clone(node));
        }
Ejemplo n.º 2
0
        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);
        }