|
|
Current Queue
|
- Assign to every node a distance value. Set it to zero for the initial node and to infinity for all other nodes.
- Mark all nodes as unvisited, except for the initial node.
- Queue the inital node.
- While the queue is not empty:
- Pop the top of the queue, making it the current node.
- For each unvisited neighbor of the current node: (shown as unvisited)
- Set the distance to the unvisited node equal to the distance to the current node, plus the distance from the current node to the unvisited node (in a square graph, the distance between any adjacent nodes is 1).
- Mark the unvisited node as visited.
- Queue the node.
- Once the queue is empty, the algorithm is finished.
|