- public class BubbleSort {
- public static void sortiere(int[] x) {
- boolean unsortiert=true;
- int temp;
- while (unsortiert){
- unsortiert = false;
- for (int i=0; i < x.length-1; i++)
- if (x[i] > x[i+1]) {
- temp = x[i];
- x[i] = x[i+1];
- x[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[i]+" ");
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/040220132070.html
来源: http://www.codesnippet.cn/detail/040220132070.html