我决定用洪水填充算法我的应用程序,使用维基百科这个伪代码:实施洪水填充算法
Flood-fill (node, target-color, replacement-color):
1. Set Q to the empty queue.
2. If the color of node is not equal to target-color, return.
3. Add node to Q.
4. For each element n of Q:
5. If the color of n is equal to target-color:
6. Set w and e equal to n.
7. Move w to the west until the color of the node to the west of w no longer matches target-color.
8. Move e to the east until the color of the node to the east of e no longer matches target-color.
9. Set the color of nodes between w and e to replacement-color.
10. For each node n between w and e:
11. If the color of the node to the north of n is target-color, add that node to Q.
If the color of the node to the south of n is target-color, add that node to Q.
12. Continue looping until Q is exhausted.
13. Return.
我在做正常的,直到我打的“继续循环,直到Q是累”。 我不太明白。 Q如何用尽?
但是,向Q添加节点是否会扩展For循环的迭代范围?我认为还有另一种语言,在类似的情况下,如果我这样做,我会得到一个错误... – Voldemort 2011-02-05 20:55:39