开发者社区 问答 正文

递归算法求数组中的最大值为什么没输出

#include "One.h" int max(int a[],int left,int right) { int best; best=left; while(left<=right) { if(a[best]

展开
收起
知与谁同 2018-07-22 18:55:35 1485 分享 版权
1 条回答
写回答
取消 提交回答
  • 递归不是这样的,改这样就可以了: int max(int a[],int left,int right){
        if(left==right) return a[left];
        int value=a[left],otherValue=max(a,left+1,right);
        return value>otherValue?value:otherValue;
    }

    2019-07-17 22:54:53
    赞同 展开评论
问答分类:
问答标签:
问答地址: