diff options
author | Toby Vincent <tobyv13@gmail.com> | 2021-04-20 02:28:19 +0000 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2021-04-20 02:28:19 +0000 |
commit | 798aec5e24b847ce9f56ef69793b3c407cbd2a6f (patch) | |
tree | 5ef5704e79a1e4b1c327da4303c06193bbff7969 | |
parent | 1983882323827c48e5f8dd714d38319f35bb0cc3 (diff) |
added DeepCopy functions
-rw-r--r-- | Edge.cs | 6 | ||||
-rw-r--r-- | Vertex.cs | 6 |
2 files changed, 12 insertions, 0 deletions
@@ -15,6 +15,12 @@ namespace Graph Weight = weight; } + public Edge<T> DeepCopy() + { + Edge<T> other = (Edge<T>)this.MemberwiseClone(); + return other; + } + public int CompareTo(Edge<T> edge) => Weight.CompareTo(edge.Weight); @@ -22,6 +22,12 @@ namespace Graph public Vertex(int id, List<Edge<T>> edges) : this(id) => Edges = edges; + public Vertex<T> DeepCopy() + { + Vertex<T> other = (Vertex<T>)this.MemberwiseClone(); + other.Edges = Edges.ConvertAll(edge => new Edge<T>(edge.U, edge.V, edge.Weight)); + return other; + } public int CompareTo(INode<T> node) => Key.CompareTo(node.Key); |