/// <summary> /// This adds an edge to the graph while adding a weight with the inputted value /// </summary> /// <param name="root">The first node</param> /// <param name="addNode">The second node</param> /// <param name="value">The weight of the edge</param> public void AddEdge(WeightedNode root, WeightedNode addNode, int value) { root.Children.Add(addNode); root.WeightedChildren.Add(new Dictionary <WeightedNode, int> { { addNode, value } }); addNode.Children.Add(root); addNode.WeightedChildren.Add(new Dictionary <WeightedNode, int> { { root, value } }); if (!Nodes.Contains(root)) { Nodes.Add(root); } if (!Nodes.Contains(addNode)) { Nodes.Add(addNode); } }
/// <summary> /// This returns the neighbors of the given node with weights attatched /// </summary> /// <param name="root">The node to check for neighbors</param> /// <returns>The list of neighbors and their weighted edges</returns> public List <Dictionary <WeightedNode, int> > GetNeighbors(WeightedNode root) { return(root.WeightedChildren); }