Note, that closed vertices are removed from the neigbourhood before joining with open vertices. The algorithm stops as soon as the set of open vertices is empty. Coloring First, we program the graph coloring algorithm using the above presented general schema. This algorithm corresponds to the well known algorithm that colors one vertex and, then, it colors the vertex's neighbourhood and so on. Remind, that Dijkstra's algorithm finds minimal distance to all vertices in the graph from given vertex.
Generalization can simplify the program development and understanding.