title: Flood fill using a stack
body: <p>I am using the recursive Flood fill algorithm in Java to fill some areas of a image.
  With very small images it works fine, but when de image becomes larger the JVM gives me a Stack Over Flow Error.</p>
  
  <p>That's the reason why I have to reimplement the method using a Flood Fill with my own stack. (I read that's the best way to do it in these kind of cases)</p>
  
  <p>Can anyone explain me how to code it? (if you don't have the code at hand, with the pseudo-code of the algorithm will be fine)</p>
  
  <p>I've read a lot in the Internet but I haven't understood it very well.</p>
  
  <p>EDIT: I added my recursive code</p>
  
  <pre><code>public void floodFill(int x, int y, Color targetColor,Color replacementColor) {
  
      if (img.getRGB(x, y) != targetColor.getRGB()) return;
  
      img.setRGB(x, y, replacementColor.getRGB());
      floodFill(x - 1, y, targetColor, replacementColor);
      floodFill(x + 1, y, targetColor, replacementColor);
      floodFill(x, y - 1, targetColor, replacementColor);
      floodFill(x, y + 1, targetColor, replacementColor);
  
      return;
  
  }
  </code></pre>
  
  <p>Thanks!</p>