Flood fill 算法

来源:互联网 发布:smtp服务器端口25 编辑:程序博客网 时间:2024/05/22 10:42

http://en.wikipedia.org/wiki/Flood_fill#Stack-based_recursive_implementation_.28Four-way.29


Flood-fill (node, target-color, replacement-color): 1. If target-color is equal to replacement-color, return. 2. Set Q to the empty queue. 3. Add node to the end of Q. 4. While Q is not empty:  5.     Set n equal to the last element of Q. 6.     Remove last element from Q. 7.     If the color of n is equal to target-color: 8.         Set the color of n to replacement-color. 9.         Add west node to end of Q. 10.        Add east node to end of Q. 11.        Add north node to end of Q. 12.        Add south node to end of Q. 13. Return.

0 0