


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



package sorting2; import java.util.Random; import java.util.Scanner; public class Buble { static Random random = new Random(); static Scanner in = new Scanner(System.in); public static void main(String[] args) { int array[] = new int[10000]; for (int i = 0; i < array.length; i++) { array[i] = CreateArray(); } BubleSort(array); } public static int CreateArray() { return (random.nextInt(10000)) ; } public static void tampil(int a[]) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } System.out.println(" "); System.out.println(); } public static void BubleSort(int a[]) { int flag = 0; int temp = 0; for (int i = 0; i < a.length; i++) { for (int j = 0; j < 10000; j++) { if (a[i] <= a[j]){ Swap(a, temp, i, j); } } tampil(a); } } public static void Swap(int a[], int temp, int i, int j) { temp = a[i]; a[i] = a[j]; a[j] = temp; } }
package sorting2; import java.util.Random; import java.util.Scanner; public class Insertion {