递归方法中的基本情况 [英] Base case in a recursive method

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

问题描述

这里有一个关于递归方法中基本情况或停机情况的理论问题,它的标准是什么?

A theoretical question here about the base or halting case in a recursive method, what's its standards?

我的意思是,里面没有正文,只是一个 return 语句是正常的吗?

I mean, is it normal not to have body in it, just a return statement?

是不是一直都是这样的:

Is it always like the following:

if (input operation value)
    return sth;

你有什么不同的想法吗?

Do you have different thoughts about it?

推荐答案

递归函数的模式是它们看起来像这样:

The pattern for recursive functions is that they look something like this:

f( value ) 
   if ( test value )
      return value
   else
      return f( simplify value )

对于一般情况,我认为您只能说更多.

I don't think you can say much more than that about general cases.

这篇关于递归方法中的基本情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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