reneargento/algorithms-sedgewick-wayne

Exercise 4.1.3

bitflame opened this issue · 2 comments

Hi Rene,
Hope all is well. I wonder why this exercise can not be done with instantiating another graph object, and adding edges to it by looping through the vertices, and their edges of the original. Is it because of how the question was worded, or is my way missing something?
Also, thank you so much, for creating this repo and collaborating with the users.
Regards-
Sean

Hi Sean, I am glad the repository is being useful to you.
I didn't instantiate a new graph object because in this exercise we are implementing a constructor method.
Usually on constructor methods we pass parameters whose values are assigned to the instance variables of the class.
In this case, we already have the variables vertices, edges and adjacent inside the CopyGraph class. So it makes more sense to just assign them the values of the graph passed as a parameter than to instantiate a new graph object.