fork download
  1. <?php
  2. function divideEtImpera($arr, $lo, $hi, &$min, &$max) {
  3.  
  4. if($lo == $hi) {
  5.  
  6. $min = $max = $arr[ $lo ];
  7. } else {
  8.  
  9. $m = ($lo + $hi) >> 1;
  10. divideEtImpera($arr, $lo, $m, $x, $a);
  11. divideEtImpera($arr, $m + 1, $hi, $y, $b);
  12. if($x < $y) $min = $x;
  13. else
  14. $min = $y;
  15. if($a > $b) $max = $a;
  16. else
  17. $max = $b;
  18. }
  19. };
  20.  
  21. $arr = array(1,2,87,33,11,34,91,71);
  22.  
  23. divideEtImpera($arr, 0, sizeof($arr) - 1, $min, $max);
  24.  
  25. echo"MIN = ". $min;
  26. echo"\n";
  27. echo"MAX = ". $max;
  28. echo"\n";
  29. ?>
Success #stdin #stdout 0.02s 25972KB
stdin
Standard input is empty
stdout
MIN = 1
MAX = 91