Skip to content

Instantly share code, notes, and snippets.

@Fundibalus
Created September 4, 2017 10:59
Show Gist options
  • Save Fundibalus/7088220394a6fe821c73e8dff55c4256 to your computer and use it in GitHub Desktop.
Save Fundibalus/7088220394a6fe821c73e8dff55c4256 to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
/**
*
* @author B201
*/
public class Array {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ArrayList<Integer> liste = new ArrayList<>();
liste.add(1);
liste.add(10);
liste.add(4);
liste.add(12);
liste.add(2);
liste.add(3);
liste.add(17);
liste.add(5);
Sortierung s = new Sortierung();
s.BubbleSort(liste);
System.out.println(liste);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
/**
*
* @author B201
*/
public class Array {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ArrayList<Integer> liste = new ArrayList<>();
liste.add(1);
liste.add(10);
liste.add(4);
liste.add(12);
liste.add(2);
liste.add(3);
liste.add(17);
liste.add(5);
Sortierung s = new Sortierung();
s.BubbleSort(liste);
System.out.println(liste);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package array;
import java.util.ArrayList;
/**
*
* @author B201
*/
public class Sortierung {
public ArrayList<Integer> BubbleSort(ArrayList<Integer> liste) {
boolean swapped = true;
while (swapped == true) {
swapped = false;
for (int i = 1; i < liste.size(); i++) {
if (liste.get(i) < liste.get(i - 1)) {
int zahl1 = liste.get(i);
int zahl2 = liste.get(i - 1);
liste.set(i - 1, zahl1);
liste.set(i, zahl2);
swapped = true;
}
}
}
return liste;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package array;
import java.util.ArrayList;
/**
*
* @author B201
*/
public class Sortierung {
public ArrayList<Integer> BubbleSort(ArrayList<Integer> liste) {
boolean swapped = true;
while (swapped == true) {
swapped = false;
for (int i = 1; i < liste.size(); i++) {
if (liste.get(i) < liste.get(i - 1)) {
int zahl1 = liste.get(i);
int zahl2 = liste.get(i - 1);
liste.set(i - 1, zahl1);
liste.set(i, zahl2);
swapped = true;
}
}
}
return liste;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment