// The breadth-first search. private bool search() { bool found = false; Queue<Edge> curEdges = new Queue<Edge>(); Edge startEdge = new Edge(src, src, 0.0); curEdges.Enqueue(startEdge); visited[src] = true; while (curEdges.Count > 0) { Edge curEdge = curEdges.Dequeue(); parents[curEdge.NodeTo] = curEdge.NodeFrom; if (curEdge.NodeTo == tgt) { found = true; break; } foreach (Edge e in g.EdgesFromNode(curEdge.NodeTo)) { if (!visited[e.NodeTo]) { curEdges.Enqueue(e); visited[e.NodeTo] = true; } } } return found; }
// The depth-first search. private bool search() { bool found = false; Stack<Edge> curEdges = new Stack<Edge>(); Edge startEdge = new Edge(src, src, 0.0); curEdges.Push(startEdge); while (curEdges.Count > 0) { Edge curEdge = curEdges.Pop(); visited[curEdge.NodeTo] = true; parents[curEdge.NodeTo] = curEdge.NodeFrom; if (curEdge.NodeTo == tgt) { found = true; break; } foreach (Edge e in g.EdgesFromNode(curEdge.NodeTo)) if (!visited[e.NodeTo]) curEdges.Push(e); } return found; }
public void ChangeEdgeColor(Edge e, Color c) { edgeLines[e].LineColor = c; // Need to change reverse curEdge's color too in case it is drawn // over top of the line for e. foreach (Edge curEdge in g.EdgesFromNode(e.NodeTo)) { if (e.NodeFrom == curEdge.NodeTo && e.NodeTo == curEdge.NodeFrom) { edgeLines[curEdge].LineColor = c; break; } } }