我決定用洪水填充算法我的應用程序,使用維基百科這個僞代碼:實施洪水填充算法
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