@ 2017-11-15T04:52:45Z <?php
$list = [1,2,3,3,44,5,6,2,3,2,33,8,8,6,"Kanyin",9,24,21,3,'adeola3','Adeola3',44,5,102,33,43,"Kanyin", "Kanyinsola", "Adeola", "adeola", "Adeolas", "Adeola1","Adeola"];
//bubbleSort($list);
binarySearch( 44, $list, 1, 5);
function binarySearch( $target, array $list, $low, $high )
{
if( $low > $high )
{
echo "Not found!";
return false;
}
$middle = ( $low + $high ) / 2;
if( $target == $list[$middle] )
{
echo "Found $target at $middle";
return true;
}
else if($target > $list[ $middle ])
{
return binarySearch( $target, $list, $middle + 1, $high );
}
else{
return binarySearch( $target, $list, $low, $middle - 1 );
}
}
function bubbleSort( array $lst )
{
$numList = count( $lst );
$swapped = false;
do{
$swapped = false;
for( $i=0; $i < $numList - 1; $i++ )
{
if( $lst[$i] > $lst[$i+1]){
$temp = $lst[$i];
$lst[$i] = $lst[$i+1];
$lst[$i+1] = $temp;
$swapped = true;
}
}
} while ( $swapped == true);
echo ( implode(" ", $lst));
}
//selectionSort( $list );
function selectionSort( array $lst )
{
$numList = count( $lst );
for( $i=0; $i < $numList; $i++ )
{
$index = 0;
$smallest = $lst[$i];
for( $j = $i; $j < $numList; $j++ )
{
if( $lst[$j] < $smallest )
{
$smallest = $lst[$j];
$index = $j;
}
$temp = $lst[$i];
$lst[$i] = $smallest;
$lst[$index] = $temp;
}
echo ( implode(" ", $lst));
}
}
//linearSearch( $list, 3 );
function linearSearch( array $lst, $target )
{
$numList = count( $lst );
for( $i=0; $i < $numList; $i++ )
{
if( $lst[$i] == $target )
{
echo "Found $target at $i\n";
}
}
}
//factoral(6);
function factoral( $n )
{
if( $n == 1 )
{
return 1;
}
echo $n * factoral( $n -1 );
}
function chessboard()
{
for($i=0; $i<6; $i++)
{
echo "$i X0 :";
for($j=0; $j<$i; $j++)
{
echo "*";
}
echo "\n";
}
}
//chessboard();
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.4 , 8.3.6 - 8.3.7 Deprecated: Implicit conversion from float 4.5 to int loses precision in /in/k5F7h on line 20
Found 44 at 4.5 Output for 8.3.5 Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Deprecated: Implicit conversion from float 4.5 to int loses precision in /in/k5F7h on line 20
Found 44 at 4.5 Output for 7.0.0 - 7.0.25 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 Found 44 at 4.5 preferences:dark mode live preview
155.18 ms | 402 KiB | 225 Q