码迷,mamicode.com
首页 > 其他好文 > 详细

CC150 8.6

时间:2014-12-02 12:00:20      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:interview

8.6 Implement the “paint fill” function that one might see on many image editing programs. That is, given a screen (represented by a 2 dimensional array of Colors), a point, and a new color, fill in the surrounding area until you hit a border of that color.

interface Panter
{
}

class Pos
{
  int x,
  int y, 
  void paint(Panter p);  
  boolean isPainted();
}

paint(Set<Pos> borders, Pos start, Panter panter)
{
  if (borders.contains(start))
    return;
  
  if (start.isPainted())
    return;
    
  start.paint(panter);
    
  paint(borders, start.up(), panter);
  paint(borders, start.down(), panter);
  paint(borders, start.left(), panter);
  paint(borders, start.right(), panter);
}


Other other like BFS tree.

CC150 8.6

标签:interview

原文地址:http://7371901.blog.51cto.com/7361901/1585341

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!