Thursday, May 17, 2007

-=Bubble Sort=-

i've been extra busy with exams and my project report (18,000 words) over the past few weeks.
as part of my algorithms revision i have been implementing the basic algorithms in php to help me remember them.

Bubble sort is whereby you pass through the array n times, where n = (array_length -1).
Each time you pass through you compare the 1st cell of the array with the 2nd, if the first is higher then you can swap them. repeat with the 2nd and 3rd cells etc...
This method pushes the largest number in the array to the end, and in the 2nd pass pushes the 2nd largest to the penultimate cell etc.

you can see the php running here (note that on each iteration the array has been printed to show workings)

and the php code can be found here

-=b0uj=-

No comments: