Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include "maxmin.h"
- #include <stdio.h>
- //pole-pole na najdenie maxima a minima
- // n -velkost pola
- maxmin MAXMIN(int *pole,int n){
- maxmin total;
- maxmin right;
- maxmin left;
- if(n==1){
- total.max=pole[0];
- total.min=pole[0];
- return total; }
- else if(n==2){
- if(pole[0]<pole[1]){total.max=pole[1];total.min=pole[0];return total;}
- else{total.max=pole[0];total.min=pole[1];return total;}
- }
- else{
- if(n%2==0){
- left=MAXMIN(pole,(n/2));
- right=MAXMIN(&pole[n/2],(n/2));}
- else{
- left=MAXMIN(pole,(n/2));
- right=MAXMIN(&pole[n/2],(n/2)+1);}
- }
- if(left.max>right.max)
- total.max=left.max;
- else
- total.max=right.max;
- if(left.min<right.min)
- total.min=left.min;
- else
- total.min=right.min;
- return total;
- }
Add Comment
Please, Sign In to add comment