Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Random;
- public class Main {
- public static void main(String[] args) {
- /////////
- //SETUP//
- /////////
- int[] arrayDummyData; //reference. Will hold our array of random ints
- ArrayList<Integer> AL_SortedDeck = new ArrayList<Integer>(); //create an arraylist to sort into
- Random rand = new Random(); //Set up the random constructor
- arrayDummyData = new int[10]; //create empty array with space for ten ints
- //create the array
- int i = 0;
- while (i < arrayDummyData.length){
- //pick a value between 1 and 10, inclusive
- int randNum = rand.nextInt((100 - 1) + 1) + 1;
- arrayDummyData[i] = randNum; //dummy list
- AL_SortedDeck.add(randNum); //Arraylist List
- System.out.println(i + ": " + AL_SortedDeck.get(i));
- i++;
- }//while
- System.out.println("---");
- int x = 0;
- int y = 1;
- int a;
- int b;
- int counter = 0;
- sort: while (x < AL_SortedDeck.size()){
- if (AL_SortedDeck.get(y) < AL_SortedDeck.get(x)) {
- //System.out.println("Swapping index: " + x + " and " + y);
- a = AL_SortedDeck.get(y);
- b = AL_SortedDeck.get(x);
- AL_SortedDeck.set(x, a);
- AL_SortedDeck.set(y, b);
- counter = 0;
- x++;
- y++;
- if (x >= AL_SortedDeck.size()){ y = 1; x=0;}
- if (y >= AL_SortedDeck.size()){ y = 1; x=0;}
- continue sort;
- }//endIF
- //System.out.println("No Swap needed");
- x++;
- y++;
- if (x >= AL_SortedDeck.size()){ y = 1; x=0; }
- if (y >= AL_SortedDeck.size()){ y = 1; x=0; }
- counter++;
- if (counter > AL_SortedDeck.size()){break sort;}
- continue sort;
- } //while
- System.out.println(AL_SortedDeck);
- }//staticmainstringsargs
- }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement