Mutual Recursion Question

梦想与她 提交于 2019-12-24 05:12:30

问题


How do I change two functions that are Mutual Recursive to each other to make them into a linear recursion? Do I have to have both the methods in a single method?


回答1:


You should be able to simply "inline" the implementation of the second method, into the first method.

That is,

public static void methA() {
    // snippet 1

    methB();

    // snippet 2
}

public static void methB() {
    // snippet 3

    methA();

    // snippet 4
}

becomes

public static void methAB() {
    // snippet 1

    // snippet 3

    methAB();

    // snippet 2

    // snippet 4
}

If the second method is long, and called from multiple points in the first method, it may get messy though.



来源:https://stackoverflow.com/questions/4950704/mutual-recursion-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!