简体   繁体   English

即使在递归调用之后也不会发生递归

[英]Recursion does not take place even after recursive call

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;说明:View v、Graphics g 和Point internal 是自定义对象;

If the function has been recursive in nature it might have printed "Exit Case when the exit case is reached"如果函数本质上是递归的,它可能会打印“到达退出案例时退出案例”

Code execution results:代码执行结果:

在此处输入图片说明

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.它没有做的是打印“退出案例”,因为pixelColor永远不会为 0。调试您的代码/打印pixelColor的值并尝试找出为什么它永远不会为 0。

变量pixelColor似乎没有达到 0 这就是为什么你的代码没有打印“退出案例”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM