int min(int var[],int t){ if(t==0) return var[0]; else{ int m = min(var,t-1); return m<var[t-1]?m:var[t-1]; } } int min2(int var[],int t){ int m = var[0]; for(int i = 1;i<t;i++){ if(var[i]<m) m = var[i]; } return m; } int main(int argc, _TCHAR* argv[]) { int var[]={1,2,4,5,6,7,8,19}; int m = min(var,8); cout<<m<<endl; int m2 = min2(var,8); cout<<m2<<endl; }
|
递归模型一定要有递归出口,也就是递归的终止条件,不然产生无穷递归。
阅读(822) | 评论(0) | 转发(0) |