home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / Bubble.php < prev    next >
Encoding:
PHP Script  |  2001-07-02  |  882 b   |  36 lines

  1. //**************************************
  2.     //     
  3.     // Name: Bubble Sort
  4.     // Description:This is a simple bubbleso
  5.     //     rt that takes 2 arrays as argument.The f
  6.     //     irst one is the actual data used for sor
  7.     //     ting, the second is data that will "tag 
  8.     //     along" with the first array, for instanc
  9.     //     e a descriptive text about the data in t
  10.     //     he first array. by Petter Nilsen.
  11.     // By: PHP Code Exchange
  12.     //**************************************
  13.     //     
  14.     
  15.     <?php
  16.     function bubblesort($a1,$a2)
  17.     {
  18.     for($i = sizeof($a1); $i >= 1; $i--)
  19.     {
  20.     for($j = 1; $j <= $i; $j++)
  21.     {
  22.     if($a1[$j-1] > $a1[$j])
  23.     {
  24.     $t = $a1[$j-1];
  25.     $t2 = $a2[$j-1];
  26.     $a1[$j-1] = $a1[$j];
  27.     $a2[$j-1] = $a2[$j];
  28.     $a1[$j] = $t;
  29.     $a2[$j] = $t2;
  30.     }
  31.     }
  32.     }
  33.     }
  34.     ?>
  35.  
  36.