function kMax(&$a, $k) { $right = count($a) - 1; do { $n = partition($a, 0, $right); if ($n == count($a) - $k) { return $a[$n]; } else { if ($n == $right) { $right--; } } } while ($right >= 0); }
function quicksort(&$A, $p, $r) { if ($p < $r) { $q = partition($A, $p, $r); quicksort($A, $p, $q - 1); quicksort($A, $q + 1, $r); } }
function _quicksort(array &$input, $lo, $hi) { if ($lo < $hi) { $pivot = partition($input, $lo, $hi); _quicksort($input, $lo, $pivot - 1); _quicksort($input, $pivot + 1, $hi); } }
function quickSort(&$array, $left, $right) { if ($left >= $right) { return; } $pivot = partition($array, $left, $right); quickSort($array, $left, $pivot - 1); quickSort($array, $pivot + 1, $right); }
function quicksort(array &$array, $start, $end, $value) { if ($start >= $end) { return; } $pivotStartIndex = pickPivot($array, $start, $end); $pivotNewIndex = partition($array, $start, $end, $pivotStartIndex, $value); quicksort($array, $start, $pivotNewIndex - 1, $value); quicksort($array, $pivotNewIndex + 1, $end, $value); }
function quickSort(&$arr, $leftIndex, $rightIndex) { $index = partition($arr, $leftIndex, $rightIndex); if ($leftIndex < $index - 1) { quickSort($arr, $leftIndex, $index - 1); } if ($index < $rightIndex) { quickSort($arr, $index, $rightIndex); } }
function separateEvenAndOddNumbers($array) { $newArray; list($even, $odd) = partition($array, function ($even) { return $even % 2 == 0; }); $newArray[0] = $even; $newArray[1] = $odd; return $newArray; }
function quickSort(array &$arr, $startIndex = 0, $stopIndex = null) { $stopIndex = $stopIndex !== null ? $stopIndex : count($arr) - 1; if ($stopIndex - $startIndex <= 1) { return $arr; } $pivotIndex = choosePivot($arr, $startIndex, $stopIndex); $pivotIndex = partition($arr, $pivotIndex, $startIndex, $stopIndex); quickSort($arr, 0, $pivotIndex - 1); quickSort($arr, $pivotIndex + 1, $stopIndex); }
function order_statistics($list, $i) { if (count($list) == 1) { return $list[0]; } $pivot = array_pop($list); list($left, $right) = partition($list, $pivot); if (count($left) >= $i) { return order_statistics($left, $i); } else { return order_statistics($right, $i - count($left)); } }
function kthLargest($arr, $k) { $left = 0; $right = count($arr) - 1; while (true) { $pivIndex = ($left + $right) / 2; $newPiv = partition($arr, $left, $right, $pivIndex); if ($newPiv == $k) { return $arr[$newPiv]; } elseif ($newPiv < $k) { $left = $newPiv + 1; } else { $right = $newPiv - 1; } } }
function order_statistic($list, $i) { if (count($list) == 1) { return $list[0]; } // ceate a non empty partitions // extract the pivot from the list and // in case one of the sub-lists is empty // add the pivot there! $pivot = array_pop($list); list($left, $right) = partition($list, $pivot); if (count($left) >= $i) { return order_statistic($left, $i); } else { return order_statistic($right, $i - count($left)); } }
$partition = array(); $mark = 0; for ($px = 0; $px < $p; $px++) { $incr = $px < $partrem ? $partlen + 1 : $partlen; $partition[$px] = array_slice($list, $mark, $incr); $mark += $incr; } return $partition; } $part = array(); $array = file($argv[3], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (isset($argv[5])) { $proxies = file($argv[5], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } $childcount = $argv[4]; $part = partition($array, $childcount); $shm_id = shmop_open(23377332, "c", 0666, 1024); shmop_close($shm_id); for ($i = 0; $i < $childcount; $i++) { $pid = pcntl_fork(); if ($pid == -1) { echo "failed to fork on loop {$i} of forking\n"; exit; } else { if ($pid) { continue; } else { $sem = sem_get(13377331, 1, 0666, 1); $shm_id = shmop_open(23377332, "c", 0666, 1024); while (true) { foreach ($part[$i] as $line) {
ini_set('html_errors', 0); ini_set('display_errors', 1); $GLOBALS["VERBOSE"] = true; } include_once dirname(__FILE__) . "/frame.class.inc"; include_once dirname(__FILE__) . "/class.unix.inc"; if (isset($_GET["whitelist"])) { whitelist(); exit; } if (isset($_GET["build"])) { build(); exit; } if (isset($_GET["partition"])) { partition(); exit; } while (list($num, $line) = each($_GET)) { $f[] = "{$num}={$line}"; } writelogs_framework("unable to understand query !!!!!!!!!!!..." . @implode(",", $f), "main()", __FILE__, __LINE__); die; //----------------------------------------------------------------------------------------------------------------------------------- function squidclient_mgr_storedir() { $unix = new unix(); $data = $unix->squidclient("storedir", true); @unlink("/usr/share/artica-postfix/ressources/logs/web/storedir.cache"); @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/storedir.cache", $data); }
* Date: 24.11.15 * Time: 11:32 */ $array = [4, 7, 3, 2, 8, 5]; //Merge Sort function partition($array) { $smaller = []; $bigger = []; $newArray = []; $len = count($array) - 1; $lastElement = $array[$len]; for ($i = 0; $i < $len; $i += 1) { if ($array[$i] <= $lastElement) { $smaller[] = $array[$i]; } else { $bigger[] = $array[$i]; } } $lenSmaller = count($smaller) - 1; for ($i = 0; $i <= $len; $i += 1) { if ($i <= $lenSmaller) { $newArray[] = $smaller[$i]; } else { $newArray[] = $bigger[$i]; } } return $newArray; } $result = partition($array); print_r($result);
function quick(&$data, $low, $high) { if ($low < $high) { $point = partition($data, $low, $high); quick($data, $low, $point - 1); quick($data, $point + 1, $high); } }