Computerhilfen.de Logo
Forum
Tipps
News
Frage stellen

Java Bubblesort

Hallo Leute! ;D

Brauche mal hilfe:

Ich finde meinen Fehler einfach nicht... als Ergebnis wird mir immer 0 angezeigt.


public class Bubblesort {

   private static int i;
   /* Beginn des Bubblesorts! */
   
   public static void sortiere(int[] n) {
      boolean unsortiert = true;
      int temp;
      
      while (unsortiert) {
         unsortiert = false;
         for (int i= 0; i < n.length -1; i++);
         for (int j= 1; j< n.length ; j++);
         if (n > n[i+1])
         {
            
            temp = n;
            
            n = n[i+1];
            
            n[i+1] = temp;
            
            unsortiert = true;
            
         }
      }
   }
   public static void main (String[] args) {
      int[] liste = {0, 1, 23, 2, 33, 43, 12};
      sortiere(liste);
      for (int i = 0; i < liste . length; i++);
      System.out.print( liste + " ");
      
   }
   
   
}


PS: Habe damit erst 1 Woche Erfahrung ;=)

Danke schonmal im Vorrus!!


Antworten zu Java Bubblesort:

Hat dir diese Antwort geholfen?

Danke ButtonHilfreiche Antwort Button

Warum benutzt du die for-Schleife mit j, wenn du j nicht weiter verwendest?

Hier der code:

Zitat

public class BubbleSort
{
   public static void sortiere(int[] n)
   {
    boolean unsortiert=true;
    int temp;
     
     while (unsortiert)
     {
       unsortiert = false;
       for (int i=0; i < n.length-1; i++)
       {
         if (n > n[i+1])
         {                     
         temp       = n;
         n       = n[i+1];
         n[i+1]     = temp;
         unsortiert = true;
         }         
       }
     }
  }

   
   public static void main(String[] args) {
      int[] liste = {0,9,4,6,2,8,5,1,7,3};
      sortiere(liste);
      for (int i=0; i<liste.length; i++)
         System.out.print(liste+" ");   
   }
}

  
« Letzte Änderung: 29.03.12, 15:38:33 von SelfmadeIce »

« Benötige etwas Hilfe bei C#C++ Anfängerfrage: Variablen in Gänsefüßchen »
 

Schnelle Hilfe: Hier nach ähnlichen Fragen und passenden Tipps suchen!