Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Lesley on 18-1-2017.
- */
- import java.util.Random;
- /**
- *
- */
- @SuppressWarnings("Duplicates")
- class Sorter implements Runnable {
- private int[] array;
- private int amount = 200000;
- Sorter(int[] array) {
- this.array = array;
- }
- Sorter() {
- }
- private void sortArray(int n, int[] array) {
- int c, d, swap;
- for (c = 0; c < (n - 1); c++) {
- for (d = 0; d < n - c - 1; d++) {
- if (array[d] > array[d + 1]) /* For descending order use < */ {
- swap = array[d];
- array[d] = array[d + 1];
- array[d + 1] = swap;
- }
- }
- }
- }
- @Override
- public void run() {
- sortArray(amount / 2, array);
- }
- int[] randomArray(int amount) {
- Random random = new Random();
- int[] array = new int[amount];
- for (int i = 0; i < array.length; i++) {
- array[i] = i;
- }
- for (int i = array.length - 1; i > 0; i--) {
- int index = random.nextInt(i + 1);
- int a = array[index];
- array[index] = array[i];
- array[i] = a;
- }
- return array;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement