Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //import Prog1Tools.IOTools;
- public class BubbleSort
- {
- public static int[] randomSequence;
- public static int[] generateNewRandomArray (int x)
- {
- randomSequence = new int[x];
- for(int i = 0 ; i<randomSequence.length ; i++)
- {
- double DezimalRandom = Math.random();
- randomSequence [i] = (int)(DezimalRandom*10);
- }
- return randomSequence;
- }
- public static void main (String[] args)
- {
- //int customlength = IOTools.readInt("Was ist die gewünschte Array Länge?: ");
- generateNewRandomArray (20);
- printArrayToConsole(randomSequence);
- sortArray(randomSequence);
- //printArrayToConsole(randomSequence);
- }
- public static int[] printArrayToConsole(int[] x)
- {
- for(int i = 0 ; i<x.length ; i++)
- {
- System.out.print(x[i]);
- }
- System.out.println(" "); //Absatz
- return x;
- }
- public static int[] sortArray(int[] a)
- {
- int n = a.length-1 ;
- boolean vertauscht = false;
- do
- {
- for(int i = 0 ; i<n ; i++)
- {
- if(a[i]>a[i+1])
- {
- int temp = a[i];
- a[i] = a[i+1];
- a[i+1] = temp;
- vertauscht = true;
- }
- }
- n = n -1;
- }
- while(vertauscht & n>=1);
- for(int i = 0 ; i<a.length ; i++)
- {
- System.out.print(a[i]);
- }
- return a ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement