next up previous
Nächste Seite: Quick-Sort Aufwärts: Grundlagen der Java-Programmierung (Vorlesung Vorherige Seite: Bubble-Sort

Bubble-Sort (II)

static void bubble_sort (int [] a) {
  // sortiert  a  aufsteigend
  for (int i=0; i<a.length; i++) {
    // füge a[i] in bereits 
    // sortiertes a[0 .. i-1] ein
    for (int j=i-1; j >= 0; j--) {
       bubble (a, j, j+1);   
    }
  }
}


static void check () {
    int a [] = { 0,5,3,1,4,2 };
    println (a); bubble_sort (a); println (a);
}



Johannes Waldmann 2004-01-30