相互递归问题 [英] Mutual Recursion Question

查看:118
本文介绍了相互递归问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改相互递归的两个函数以使其成为线性递归?我必须将两种方法都放在一个方法中吗?

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?

推荐答案

您应该能够简单地将第二种方法的实现内联"到第一种方法中.

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

也就是说,

public static void methA() {
    // snippet 1

    methB();

    // snippet 2
}

public static void methB() {
    // snippet 3

    methA();

    // snippet 4
}

成为

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.

这篇关于相互递归问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆