lab6
This commit is contained in:
1 parent
1b564e47e9
commit
7f65ead644
44 files changed
+4582
-2
No files matched your search
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
|
||||
namespace Code.Lab6
|
||||
{
|
||||
[Serializable]
|
||||
public class Edge : IComparable<Edge>
|
||||
{
|
||||
public float cost;
|
||||
public readonly Vertex Vertex;
|
||||
|
||||
public Edge(Vertex vertex = null, float cost = 1f)
|
||||
{
|
||||
Vertex = vertex;
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
public int CompareTo(Edge other)
|
||||
{
|
||||
var result = cost - other.cost;
|
||||
var idA = Vertex.GetInstanceID();
|
||||
var idB = other.Vertex.GetInstanceID();
|
||||
if (idA == idB) return 0;
|
||||
return (int)result;
|
||||
}
|
||||
|
||||
public bool Equals(Edge other)
|
||||
{
|
||||
return other.Vertex.id == Vertex.id;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var other = (Edge)obj;
|
||||
return other != null && other.Vertex.id == Vertex.id;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Vertex.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user