-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.cs
70 lines (57 loc) · 1.42 KB
/
Node.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Djikstra
{
public class Node : IComparable
{
private string _name;
public Node(string name)
{
_name = name;
}
// What is the equivalent of unsigned int in C# ?
public int Distance { get; set; }
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
public List<Node> Neighbors { get; set; }
public List<Edge> Edges { get; set; }
public Node Previous { get; set; }
public bool IsVisited { get; set; }
public bool DoesEdgeExist(Node neighbor)
{
foreach (Edge edge in Edges)
{
if ((edge.EndNode == neighbor) || (edge.StartNode == neighbor))
{
return true;
}
}
return false;
}
public int CompareTo(object other)
{
Node otherNode = other as Node;
if (this.Distance < otherNode.Distance)
{
return -1;
}
else if (this.Distance > otherNode.Distance)
{
return 1;
}
return 0;
}
}
}