Guest User

Untitled

a guest
Mar 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. # include "maxmin.h"
  2. #include <stdio.h>
  3.  
  4. //pole-pole na najdenie maxima a minima
  5. // n -velkost pola
  6.   maxmin  MAXMIN(int *pole,int n){
  7.         maxmin total;
  8.       maxmin right;
  9.       maxmin left;
  10.  
  11.     if(n==1){
  12.         total.max=pole[0];
  13.         total.min=pole[0];
  14.         return total; }
  15.  
  16.         else if(n==2){
  17.         if(pole[0]<pole[1]){total.max=pole[1];total.min=pole[0];return total;}
  18.            else{total.max=pole[0];total.min=pole[1];return total;}
  19.         }
  20.         else{
  21.  
  22.         if(n%2==0){
  23.         left=MAXMIN(pole,(n/2));
  24.         right=MAXMIN(&pole[n/2],(n/2));}
  25.  
  26.          else{
  27.         left=MAXMIN(pole,(n/2));
  28.  
  29.         right=MAXMIN(&pole[n/2],(n/2)+1);}
  30.             }
  31.  
  32.         if(left.max>right.max)
  33.             total.max=left.max;
  34.             else
  35.             total.max=right.max;
  36.  
  37.         if(left.min<right.min)
  38.             total.min=left.min;
  39.             else
  40.             total.min=right.min;
  41.  
  42.  
  43.         return total;
  44. }
Add Comment
Please, Sign In to add comment