Skip to content

Instantly share code, notes, and snippets.

@manish-manghwani
Created July 7, 2019 20:55
Show Gist options
  • Select an option

  • Save manish-manghwani/772af678c82e74b8d7d669c7056d9915 to your computer and use it in GitHub Desktop.

Select an option

Save manish-manghwani/772af678c82e74b8d7d669c7056d9915 to your computer and use it in GitHub Desktop.
Trying to find why allocate memory exceeds 500MB even when there are 2 entries
<?php
function quickSort($unsortedArray){
$leftArray = [];
$rightArray = [];
$arrayCount = count($unsortedArray);
//considering middle of array
$pivot = $unsortedArray[(int)floor($arrayCount / 2)];
for($i = 0; $i < $arrayCount ; $i++){
if($unsortedArray[$i] < $pivot){
array_push($leftArray,$unsortedArray[$i]);
}else{
array_push($rightArray,$unsortedArray[$i]);
}
}
$tempRight = quickSort($rightArray);
$sortedRight = array_push($pivot,$tempRight);
$tempLeft = quickSort($leftArray);
$sortedLeft = array_push($tempLeft,$sortedRight);
return array_push($sortedRight,$sortedRight);
}
$unsortedArray = [200,100];
var_dump($unsortedArray);
$sortedArray = quickSort($unsortedArray);
var_dump($sortedArray);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment