How to build a directed graph of user connections and then add a copy functionality
Anonymous User
391

Assume that we have a User class with minimum basic sttributes like id and follows(a list of users that he/she follows). What are the best ways to represent this type system/graph.

class User {
	String id;
	List<User> follows; 
}

Now we have to make copy method which copies this entire graph of users. This part confuses me is, from where to start copying? Since relationship is nested in nature with possible cycles, we might endup with deadlock.

Comments (2)