Posted By

dalcacer on 03/11/10


Tagged

sort bubblesort


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

indra
kentonnewby
larste


Bubblesort


 / Published in: Java
 

  1. public class BubbleSort {
  2. public static void sortiere(int[] x) {
  3. boolean unsortiert=true;
  4. int temp;
  5.  
  6. while (unsortiert){
  7. unsortiert = false;
  8. for (int i=0; i < x.length-1; i++)
  9. if (x[i] > x[i+1]) {
  10. temp = x[i];
  11. x[i] = x[i+1];
  12. x[i+1] = temp;
  13. unsortiert = true;
  14. }
  15. }
  16. }
  17.  
  18. public static void main(String[] args) {
  19. int[] liste = {0,9,4,6,2,8,5,1,7,3};
  20. sortiere(liste);
  21. for (int i=0; i<liste.length; i++)
  22. System.out.print(liste[i]+" ");
  23. }
  24. }

Report this snippet  

You need to login to post a comment.