deep copying a graph structure
问题 I have a graph class with Node's, where each Node can connect to others: public class Node { List<Node> connections; } I would like to make a deep copy of the entire graph. As a first attempt, I tried making a copy constructor like: public Node(Node other) { connections = new ArrayList<Node>(); for (Node n : other.connections) { connections.add(new Node(n)); } } So deep copying a graph would just be: public Graph deepCopy () { Graph g = new Graph(); g.nodes = new ArrayList<Node>(); for (Node