Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BubleSort
- {
- private $array;
- function __construct($array2)
- {
- $this->array = $array2;
- echo '<br />';
- }
- public function posortuj()
- {
- $a=true;
- $tmp;
- $j=0;
- while ($a)
- {
- $a= false;
- $j++;
- for ($i=0; $i < count($this->array) - $j; $i++)
- {
- if ($this->array[$i] > $this->array[$i + 1])
- {
- $tmp = $this->array[$i];
- $this->array[$i] = $this->array[$i + 1];
- $this->array[$i + 1] = $tmp;
- echo '<br />';
- $a= true;
- }
- }
- }
- return $this->array;
- }
- }
- $tablica = array(21,2,6,5,3,6,7);
- $sortowanie = new BubleSort($tablica);
- print_r( $sortowanie->posortuj());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement