![]() |
![]() |
|
|
|||||||
| Programmierung Rat & Tat für Programmierer |
![]() |
|
|
Themen-Optionen | Ansicht |
|
|
|
|
#1 |
|
Elite
![]() Registriert seit: 07.02.2003
Beiträge: 1.037
|
public class Bubblehope {
static int[] zahlen = new int[4]; static boolean sorted = false; static int zaehler = 0, temp = 0; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int u = 55; for (int i=0; i < zahlen.length; i++) { zahlen[i] = u--; } for (int i=0; i< zahlen.length;i++){ sorted=false; zaehler=0; zahlen = bubblesort(); } for (int i=0; i < zahlen.length-1; i++) { if (zahlen[i] > zahlen[i+1]) { System.out.println("unsortiert!"); break; } } for (int i=0; i < zahlen.length; i++) { System.out.println(zahlen[i]); } } public static int[] bubblesort() { //System.out.println(zaehler); if (!sorted) { sorted = true; if (zaehler >= zahlen.length-1) { return zahlen; } if (zahlen[zaehler] > zahlen[zaehler+1]) { temp = zahlen[zaehler]; zahlen[zaehler] = zahlen[zaehler+1]; zahlen[zaehler+1] = temp; sorted = false; } zaehler++; bubblesort(); } return zahlen; } } |
|
|
|
![]() |
| Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1) | |
|
|