Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class BubleSort
  2. {
  3. private $array;
  4.  
  5. function __construct($array2)
  6. {
  7. $this->array = $array2;
  8. echo '<br />';
  9. }
  10.  
  11. public function posortuj()
  12. {
  13. $a=true;
  14. $tmp;
  15. $j=0;
  16. while ($a)
  17. {
  18. $a= false;
  19. $j++;
  20. for ($i=0; $i < count($this->array) - $j; $i++)
  21. {
  22. if ($this->array[$i] > $this->array[$i + 1])
  23. {
  24. $tmp = $this->array[$i];
  25. $this->array[$i] = $this->array[$i + 1];
  26. $this->array[$i + 1] = $tmp;
  27. echo '<br />';
  28. $a= true;
  29. }
  30. }
  31. }
  32. return $this->array;
  33. }
  34. }
  35.  
  36. $tablica = array(21,2,6,5,3,6,7);
  37. $sortowanie = new BubleSort($tablica);
  38. print_r( $sortowanie->posortuj());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement