Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uebung4;
- import java.util.Arrays;
- public class Sortieren {
- public static int[] bubblesort(int[] zusortieren) {
- int temp;
- for (int i = 1; i < zusortieren.length; i++) {
- for (int j = 0; j < zusortieren.length - i; j++) {
- if (zusortieren[j] > zusortieren[j + 1]) {
- temp = zusortieren[j];
- zusortieren[j] = zusortieren[j + 1];
- zusortieren[j + 1] = temp;
- }
- }
- }
- return zusortieren;
- }
- public static void main(String[] args) {
- int[] a = { 2000, 2, 45, 34, 100000, 345, 56, 78, 99, 756, 999, 0, 666, 2345, 7492, 22 };
- System.out.println("Data items in original order");
- System.out.print(Arrays.toString(a));
- System.out.println();
- System.out.println("Data items in ascending order");
- int[] a_sortiert = bubblesort(a);
- System.out.print(Arrays.toString(a_sortiert));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement