Created
April 28, 2017 20:40
-
-
Save thinkphp/b0420d67087d6d6d10a49dbe55301d30 to your computer and use it in GitHub Desktop.
computes max a b using divide et impera.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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