Some classical recursive functions

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.