*/-->
Some Classical Recursive Functions
Table of Contents
- 1. Find the maximum element of an array recursively.
In this post, I will list the commonly met recursive functions that can light
the road for further investigation into the magic world of computer science.
I am not an excellent programmer myself, but through delight practice, the
little but essential part of the RECURSIVE PROBLEMS can be understood. So I will
present some examples to illustrate what I mean.
1 Find the maximum element of an array recursively.
#define max(a,b) (a) > (b) ? (a) : (b) int f_max(int *a,int start,int end) { if (start == end) { return a[start]; } return max(a[start],f_max(a,start + 1,end)); } void test_max(void) { int a[] = { 12,1,22,56,4 }; printf("max=%d\n",f_max(a,0,4)); }
Author: wujing
Created: 2014-07-13 日 10:45
Some Classical Recursive Functions
时间: 2024-10-21 20:14:08