Commit 29556fbb authored by Tanmim Hanifa's avatar Tanmim Hanifa
Browse files

implemented method to return neighbours of node a, though not entirely working currently

parent 664f364a
No preview for this file type
......@@ -24,9 +24,15 @@ class YellowGraph : Graph {
}
public void AddEdge(Node a, Node b, int c) {
adjMatrix[a.Id,b.Id] = c; //adds cost between two nodes in the adjacency matrix to imply of a corresponding edge between the two nodes
}
if(a.Id >= adjMatrix.GetLength(0) || b.Id >= adjMatrix.GetLength(1))
{
Console.WriteLine("Matrix out of bounds"); //ensure we don't exceed the size of the matrix
} else if (c >= 0) { //Only add cost to adjMatrix if cost is postive
adjMatrix[a.Id,b.Id] = c; //adds cost between two nodes in the adjacency matrix to imply of a corresponding edge between the two nodes
}
}
public List<Node> Nodes() {
return nodes; //returns all the nodes
......@@ -34,6 +40,12 @@ class YellowGraph : Graph {
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
}
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