import java.util.Random;
public class Test {
static int arr[] = new int[30000];
public static void bubbleSort(int[] x) {
int n = x.length;
for (int pass=1; pass < n; pass++) {
for (int i=0; i < n-pass; i++) {
if (x[i] > x[i+1]) {
int temp = x[i]; x[i] = x[i+1]; x[i+1] = temp;
}
}
}
}
public static void main(String... args) {
Random r = new Random(123456L); // use the seed 123456
for (int i = 0 ; i < 30000; i++) {
arr[i] = r.nextInt(20);
}
bubbleSort(arr);
for (int i = 0 ; i <= 10; i++) {
System.out.println(" " + i + " element is " + arr[i]);
}
}
}
import java.util.Random;
public class Q26408241 {
static double arr[] = new double[30000];
public static void bubbleSort(double[] x) {
int n = x.length;
for (int pass = 1; pass < n; pass++) {
for (int i = 0; i < n - pass; i++) {
if (x[i] < x[i + 1]) {
double temp = x[i];
x[i] = x[i + 1];
x[i + 1] = temp;
}
}
}
}
public static void main(String... args) {
Random r = new Random(123456L); // use the seed 123456
for (int i = 0; i < 30000; i++) {
arr[i] = r.nextDouble()*20;
}
bubbleSort(arr);
for (int i = 0; i < 10; i++) {
System.out.println(" " + i + " element is " + arr[i]);
}
}
}
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
firstswap challenge | 20 | 77 | |
numbers ascending pyramid | 101 | 195 | |
How can I build my own IDE using ASP.NET MVC? | 2 | 45 | |
MySqlDump not dumping triggers | 1 | 31 |
Join the community of 500,000 technology professionals and ask your questions.