用递归找到数组中的最小数? [英] Find the minimum number in an array with recursion?

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

问题描述

int i = 0;
int min = x[i];
while ( i < n ){
    if ( x[i] < min ){
        min = x[i];
    }
    i++;
}
return min;

我已经编写了迭代形式来查找数组的最小数.但是我想写一个带有递归的函数.请帮忙!

I've written the iterative form to find the min number of an array. But I'd like to write a function that with recursion. Please help!

推荐答案

因为这听起来像作业,这里有一个提示:数组中的最小值要么是第一个元素,要么是 rest 的数组,以较小者为准.

Because this sounds like homework, here's a hint: The minimum value in an array is either the first element, or the minimum number in the rest of the array, whichever is smaller.

这篇关于用递归找到数组中的最小数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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