Commit d4998ef0 authored by Tanmim Hanifa's avatar Tanmim Hanifa
Browse files

Fixed errors in neighbours method, all working well

parent 29556fbb
No preview for this file type
......@@ -37,13 +37,20 @@ class YellowGraph : Graph {
public List<Node> Nodes() {
return nodes; //returns all the nodes
}
public Node nodeID(int ID){ //added extra function to return node value from only knowing its id value
foreach(Node n in nodes) //increment through all the nodes in the list of nodes
if(n.GetHashCode() == ID) //if the node is found with the corresponding id, return it
return n;
return null;
}
public List<Node> Neighbours(Node a) {
List<Node> neighbours = new List<Node>(); //creates a list nodes
for(int i = 0; i < adjMatrix.GetLength(1); i++){ //look for neighbours of node in the matrix
if(adjMatrix[a.Id, i] != 0) //if we find a cost that is not 0, it means there is an edge between the nodes
neighbours.Add(a.Id(i)); //get node and add it to the list
neighbours.Add(nodeID(i)); //get node and add it to the list
}
return neighbours; //returns all the neighbours
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment