Advertisement
yacked2

[php] BubbleSort

Mar 25th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. <?php
  2.  
  3. $input = array(5,1,3,10);
  4.  
  5. $output = Razvrsti($input);
  6.  
  7. var_dump($output);
  8.  
  9. function Razvrsti($stevila)
  10. {
  11.     $d = true;
  12.     while ($d)
  13.     {
  14.         $temp = $stevila;
  15.  
  16.         for($i=0; $i < count($stevila);$i++)
  17.         {
  18.             if($i != count($stevila)-1)
  19.             {
  20.                 if($stevila[$i+1] < $stevila[$i])
  21.                 {
  22.                     $prva = $stevila[$i];
  23.                     $druga = $stevila[$i+1];
  24.                
  25.                     $stevila[$i] = $druga;
  26.                     $stevila[$i+1] = $prva;
  27.                 }
  28.             }
  29.         }
  30.    
  31.         if ($temp == $stevila)
  32.         {
  33.             $d = false;
  34.         }
  35.     }
  36.  
  37.     return $stevila;
  38. }
  39.  
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement