public List <object> BreadthFirst(NodeD root) { List <object> order = new List <object>(); Hashtable table = new Hashtable(); Queue <NodeD> breadth = new Queue <NodeD>(); breadth.Enqueue(root); while (breadth.TryPeek(out root)) { NodeD front = breadth.Dequeue(); LinkedList <DEdge> neighbor = new LinkedList <DEdge>(); AdjList.TryGetValue(front, out neighbor); foreach (DEdge child in neighbor) { if (!table.ContainsKey(child)) { table.Add(front.Value, front.Value); breadth.Enqueue(front); order.Add(front); } } } return(order); }
public List <DEdge> GetNeighbors(NodeD vertex) { LinkedList <DEdge> neighbor = new LinkedList <DEdge>(); AdjList.TryGetValue(vertex, out neighbor); return(neighbor.ToList()); }
public void AddNode(NodeD vertices) { LinkedList <DEdge> neighbor = new LinkedList <DEdge>(); AdjList.Add(vertices, neighbor); Size = 1 + Size; }
public void AddEdge(NodeD start, NodeD end, int weight) { if (AdjList.ContainsKey(start) && AdjList.ContainsKey(end)) { LinkedList <DEdge> neighbor = new LinkedList <DEdge>(); AdjList.TryGetValue(start, out neighbor); DEdge edge = new DEdge(start, end, weight); neighbor.AddFirst(edge); AdjList[start] = neighbor; } else { throw null; } }
public DEdge(NodeD start, NodeD end, int weight) { Start = start; End = end; Weight = weight; }