summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2021-04-20 02:28:19 +0000
committerToby Vincent <tobyv13@gmail.com>2021-04-20 02:28:19 +0000
commit798aec5e24b847ce9f56ef69793b3c407cbd2a6f (patch)
tree5ef5704e79a1e4b1c327da4303c06193bbff7969
parent1983882323827c48e5f8dd714d38319f35bb0cc3 (diff)
added DeepCopy functions
-rw-r--r--Edge.cs6
-rw-r--r--Vertex.cs6
2 files changed, 12 insertions, 0 deletions
diff --git a/Edge.cs b/Edge.cs
index 9b31169..38d7f89 100644
--- a/Edge.cs
+++ b/Edge.cs
@@ -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);
diff --git a/Vertex.cs b/Vertex.cs
index 628b552..2954623 100644
--- a/Vertex.cs
+++ b/Vertex.cs
@@ -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);