Created
July 2, 2012 19:24
-
-
Save albertofem/3035119 to your computer and use it in GitHub Desktop.
Complexity Algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$test = array( | |
"1", | |
"2", | |
"3", | |
"4", | |
"5", | |
"6", | |
"7", | |
"8", | |
"9", | |
"10", | |
); | |
$test2 = array( | |
2 => "mine-2", | |
4 => "mine-4", | |
7 => "mine-7" | |
); | |
function array_shift_next(&$array, $index, $limit = null) | |
{ | |
for($i=count($array)-1; $i>$index-2; $i--) | |
{ | |
if($i+1 > $limit) | |
continue; | |
$array[$i+1] = $array[$i]; | |
} | |
$array[$index-1] = null; | |
} | |
var_dump($test); | |
foreach($test2 as $key => $value) | |
{ | |
array_shift_next($test, $key, 8); | |
} | |
foreach($test2 as $key => $value) | |
{ | |
$test[$key-1] = $value; | |
} | |
var_dump($test); | |
// complexity O(m(n+1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment