Posted by: zeePa October 29, 2008
Help me techguy/(& techgirl if he has one!)
Login in to Rate this Post:     2       ?         Liked by

Write a program that implements a method that receives an array parameter and sorts that array using the bubble-sort algorithm. The bubble-sort algorithm makes several passes through the array. On each pass, successive neighboring pairs are compared. If a pair is in decreasing order, its values are swapped: otherwise, the values remain unchanged. The technique is called a bubble sort because the smaller values gradually "bubble" their way to the top.

USE THIS ALGORITHM:

boolean changed;

do{

  changed = false;

  for(int i = 0; i < list.length - 1; i++){

    if(list[i] > list[i + 1]){ 

      swap list[i] with list[i + 1];
      changed = true; 
    }

  }
}while(changed

Read Full Discussion Thread for this article