Recursion does not take place even after recursive call

Viewed 50

Even though the function is recurssive in nature it never recurse. I am completely blank why this is happening.

public void fill(Graphics g, View v, Point interior, Color boundaryColor, Color interiorColor) {
int x = interior.getx();
int y = interior.gety();
System.out.println("x: "+x+" y: "+y);
int pixelColor = v.getPixel(x, y);//always negative or zero
    
if( pixelColor == 0) {
    System.out.println("Exit case");
    return;
}
    
if( (pixelColor != boundaryColor.getRGB()) && (pixelColor != interiorColor.getRGB())) {
    System.out.println("*");
    interior.drawPoint(g, v);
        
    int nextX, nextY;
        
    nextX = x+1;
    nextY = y;
                
    Point p= new Point(v, nextX, nextY);
        
    this.fill(g, v, p, boundaryColor, interiorColor);
}
    
}

Explanation: View v, Graphics g and Point interior are custom objects;

If the function has been recursive in nature it might have printed "Exit Case when the exit case is reached"

Code execution results:

enter image description here

2 Answers

Your function is recursing just fine as shown by the output it produces. What it isn't doing is printing "Exit case" because pixelColor is never 0. Debug your code/print the values of pixelColor and try to find out why it's never 0.

Variable pixelColor does not seems to be reaching 0 that is why your code is not printing "Exit Case"

Related