Some classical recursive functions Some classical recursive functionstable OF CONTENTS
- 1. Find the maximum element of an array recursively.
In this post, I will list the commonly met recursive functions that can lightthe road for further investigation into the magic world of computer science.
I am not an excellent programmer myself, but through delight practice, thelittle but essential part of the recursive problems can be understood. So I willpresent some examples to explain strate 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:, February 13
Emacs 24.3.1 (Org mode 8.2.6)
Validate