Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created April 28, 2017 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/b0420d67087d6d6d10a49dbe55301d30 to your computer and use it in GitHub Desktop.
Save thinkphp/b0420d67087d6d6d10a49dbe55301d30 to your computer and use it in GitHub Desktop.
computes max a b using divide et impera.
#include <stdio.h>
int max(int a, int b) {
if(a > b) return a;else return b;
};
int dei(int arr[], int lo, int hi) {
if(lo == hi) {
return arr[lo];
} else {
int a = dei(arr,lo,(lo+hi)/2);
int b = dei(arr,(lo+hi)/2+1,hi);
return max(a,b);
}
};
int main() {
int max;
int arr[10] = {0,1,2,3,91,5,6,7,8,4};
printf("%d", dei(arr,0,9));
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment