Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php bubble sort

<?php 
// PHP program for implementation 
// of Bubble Sort
  
function bubbleSort(&$arr)
{
    $n = sizeof($arr);
  
    // Traverse through all array elements
    for($i = 0; $i < $n; $i++) 
    {
        // Last i elements are already in place
        for ($j = 0; $j < $n - $i - 1; $j++) 
        {
            // traverse the array from 0 to n-i-1
            // Swap if the element found is greater
            // than the next element
            if ($arr[$j] > $arr[$j+1])
            {
                $t = $arr[$j];
                $arr[$j] = $arr[$j+1];
                $arr[$j+1] = $t;
            }
        }
    }
}
  
// Driver code to test above
$arr = array(64, 34, 25, 12, 22, 11, 90);
  
$len = sizeof($arr);
bubbleSort($arr);
  
echo "Sorted array : 
";
  
for ($i = 0; $i < $len; $i++)
    echo $arr[$i]." "; 
  
// This code is contributed by ChitraNayal.
?>
Comment

PREVIOUS NEXT
Code Example
Php :: print url in view yii2 
Php :: get raw query laravel 
Php :: format datetime ISO php 
Php :: remove first element in array php 
Php :: use class Auth larave3l 
Php :: php intl 
Php :: how to return with open model popup in laravel 
Php :: limit 1 1 in laravel query 
Php :: add custom user meta and display it in user page 
Php :: General error: 1709 Index column size too large. The maximum column size is 767 bytes. 
Php :: faker 
Php :: laravel instal 
Php :: is home page if wordpress 
Php :: route params link laravel 
Php :: install phpUnit in php by composer 
Php :: browser detection php 
Php :: laravel current date in migration 
Php :: centos update php 7 to php 8 
Php :: php dump 
Php :: image uploading and validation php 
Php :: page expire in laravel 
Php :: php clone object 
Php :: random number laravel faker 
Php :: php get last part of url 
Php :: laravel migration remove relationship from table 
Php :: php test if three values are equal 
Php :: php add to array in loop 
Php :: woocommerce get variation price range 
Php :: create view from route laravel 
Php :: datetime php 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =