Hello everyone, I am trying to work with graphs and trying to put weight on edges between one node to another.
The problem is, I don't know whether is the syntax or the procedure but it does not work.
This is my graphnode class
You can see th function public T cost that's the one I am using to add weight to edges from one node to anotherCode:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Graphs { public class GraphNode<T> { private T id; private T distance; private LinkedList<T> adjList; public GraphNode(T id) { this.id = id; adjList = new LinkedList<T>(); } public void AddEdge(GraphNode<T> to) { adjList.AddLast(to.ID); } public T ID { set { this.id = value; } get { return this.id; } } public LinkedList<T> GetAdjList() { return adjList; } public T cost { set { cost = value; } get { return cost; } } } }
here is a code which sends the cost in order to add it
I send to this method the two nodes which I want to add the weight to, then once the two nodes are present and validated it does add the cost to it from the value in distance..Code:public void AddEdge(T from, T to,T distance) { foreach (GraphNode<T> n in nodes) { if (from.Equals(n.ID)) { n.GetAdjList().AddLast(to); n.cost = distance; } } }
during the breakpoint when i get to n.cost = distance; it crashes and does not even through an erros, it just say the debugger stopped.




Reply With Quote