如何在C#中运行程序时停止递归调用 [英] How to stop the recursive call while running the program in C#

查看:80
本文介绍了如何在C#中运行程序时停止递归调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在方法中使用if语句将返回置于特定条件但是我的程序再次调用该方法,因为它是递归m + d ..这就是为什么我要求在没有调用的情况下终止整个m + d的原因m + d再次..



我尝试过:



I put the return in the specific condition using if statement within the method but my program call that method again buz it is recursive m+d.. that is why I ask to terminate the whole m+d in that condition without calling the m+d again..

What I have tried:

public void subset(string[] A, int k, int start, int currLen, bool[] used, int tot)
        {
if(---
  return    --terminate
    if (start == A.Length)
                {
                    return;
                }
                          
                used[start] = true;

                subset(A, k, start + 1, currLen + 1, used, tot);
                

                used[start] = false;
                subset(A, k, start + 1, currLen, used, tot);
            }
        }

推荐答案

说实话我不确定你的代码示例试图在这里传递什么。



我会读到这个使用C#的递归方法 [ ^ ]
To be honest I am not sure what your code sample is trying to relay here.

I would have a read of this Recursive methods using C#[^]


如果我忽略了开头if(---

return --terminate



我忽略额外的近距离支撑}



然后在我看来你的程序终止了



例如我试过:

subset(new string [] {Abc,Def},0,0,0,new bool [2], 0);



它终止了。



然而你谈到m + d而我没有明白了,虽然你递归两次调用子集...



请在您的问题中更具体。
If I ignore the beginning "if(---
return --terminate"

and I ignore the extra close brace "}"

Then it seems to me that your program terminates

So for example I tried:
subset(new string[] { "Abc", "Def" }, 0, 0, 0, new bool[2], 0);

and it terminated.

You however talked about m + d which I did not understand, though you call subset recursively twice...

Please be more specific in your question.


这篇关于如何在C#中运行程序时停止递归调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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