View Single Post
chongkeat Male
chongkeat's Avatar
Join Date: Aug 2008
Posts: 497
  #2 Old 02-12-2008 Default Re: Bubble Sort in various programming languages

I'm not familiar with PHP, but from what I see, you:

Create an array.

do for number of data in array (variable A)
do for number of data - 1, while it is larger than A (variable B)
switch the data in positions array A & B if... (OK, now I'm confused.)

A bubble sort is kinda like stepping through a list and sorting each one through? Like this?

And I don't really know this part. I know we shouldn't be spoonfed, but can you please explain with comments or something?
if ($data[$j] < $data[$j - 1]) {
$t = $data[$j];
$data[$j] = $data[$j - 1];
$data[$j - 1] = $t;
You're sorting according to the word length, right? So, I guess $data[] is something like a letter count?

*Looking up Bubble Sort*
chongkeat is offline   Reply With Quote
Page generated in 0.05641 seconds with 13 queries