[Vi]sual [so]rting [al]gorithms - PHP implementation with visual representation of each step
$ make example-bubble-sort
php bubble-sort.php 6,5,3,12,11,7
Pass 1
[5] [6] [3] [12] [11] [7]
[5] [3] [6] [12] [11] [7]
[5] [3] [6] [12] [11] [7]
[5] [3] [6] [11] [12] [7]
[5] [3] [6] [11] [7] [12]
Pass 2
[3] [5] [6] [11] [7] [12]
[3] [5] [6] [11] [7] [12]
[3] [5] [6] [11] [7] [12]
[3] [5] [6] [7] [11] [12]
[3] [5] [6] [7] [11] [12]
Pass 3
[3] [5] [6] [7] [11] [12]
[3] [5] [6] [7] [11] [12]
[3] [5] [6] [7] [11] [12]
[3] [5] [6] [7] [11] [12]
[3] [5] [6] [7] [11] [12]
Input
[6] [5] [3] [12] [11] [7]
Output (3 passes)
[3] [5] [6] [7] [11] [12]