Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Random;
  3.  
  4. public class Main {
  5.  
  6.  
  7.  
  8.  
  9. public static void main(String[] args) {
  10. /////////
  11. //SETUP//
  12. /////////
  13. int[] arrayDummyData; //reference. Will hold our array of random ints
  14. ArrayList<Integer> AL_SortedDeck = new ArrayList<Integer>(); //create an arraylist to sort into
  15. Random rand = new Random(); //Set up the random constructor
  16. arrayDummyData = new int[10]; //create empty array with space for ten ints
  17.  
  18.  
  19. //create the array
  20. int i = 0;
  21. while (i < arrayDummyData.length){
  22.  
  23. //pick a value between 1 and 10, inclusive
  24. int randNum = rand.nextInt((100 - 1) + 1) + 1;
  25. arrayDummyData[i] = randNum; //dummy list
  26. AL_SortedDeck.add(randNum); //Arraylist List
  27. System.out.println(i + ": " + AL_SortedDeck.get(i));
  28. i++;
  29.  
  30. }//while
  31. System.out.println("---");
  32.  
  33. int x = 0;
  34. int y = 1;
  35. int a;
  36. int b;
  37.  
  38.  
  39.  
  40. int counter = 0;
  41. sort: while (x < AL_SortedDeck.size()){
  42. if (AL_SortedDeck.get(y) < AL_SortedDeck.get(x)) {
  43. //System.out.println("Swapping index: " + x + " and " + y);
  44. a = AL_SortedDeck.get(y);
  45. b = AL_SortedDeck.get(x);
  46. AL_SortedDeck.set(x, a);
  47. AL_SortedDeck.set(y, b);
  48. counter = 0;
  49. x++;
  50. y++;
  51. if (x >= AL_SortedDeck.size()){ y = 1; x=0;}
  52. if (y >= AL_SortedDeck.size()){ y = 1; x=0;}
  53. continue sort;
  54.  
  55. }//endIF
  56.  
  57.  
  58. //System.out.println("No Swap needed");
  59. x++;
  60. y++;
  61. if (x >= AL_SortedDeck.size()){ y = 1; x=0; }
  62. if (y >= AL_SortedDeck.size()){ y = 1; x=0; }
  63.  
  64. counter++;
  65. if (counter > AL_SortedDeck.size()){break sort;}
  66. continue sort;
  67.  
  68. } //while
  69.  
  70. System.out.println(AL_SortedDeck);
  71.  
  72.  
  73.  
  74.  
  75. }//staticmainstringsargs
  76. }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement