Guest User

Untitled

a guest
Jun 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3.  
  4. public class Sorting {
  5. public static void main (String[] args){
  6. //Here, we initiate an array with the integers
  7. //1 through 10,000 in order.
  8. Random rgen = new Random();
  9. int[] intArray = new int[10000];
  10. for (int i=0; i<10000; i++) {
  11. intArray[i] = i+1;
  12. }
  13. //Here, we randomize the positions.
  14. for (int i=0; i<10000; i++) {
  15. int randomPosition = rgen.nextInt(10000);
  16. int temp = intArray[i];
  17. intArray[i] = intArray[randomPosition];
  18. intArray[randomPosition] = temp;
  19. }
  20. //Here, we check for the maximum in the
  21. //unsorted section of the list.
  22. int max;
  23. for (int i=9999; i>=0; i--) {
  24. max = i;
  25. for (int j=i-1; j>=0; j--)
  26. if (intArray[j]>intArray[max]) {
  27. max = j;
  28. }
  29. //Here, we swap the positions of the
  30. //maximum and the last value in the
  31. //unsorted section of the list.
  32. if (max != i) {
  33. int tmp = intArray[i];
  34. intArray[i] = intArray[max];
  35. intArray[max] = tmp;
  36. }
  37. }
  38. //Here, we output the result.
  39. for (int k=0; k<10000; k++) {
  40. System.out.println(intArray[k]);
  41. }
  42. }
  43. }
  44.  
  45. //Here, we initiate an array with the integers
  46. //1 through 10,000 in order.
  47. Random rgen = new Random();
  48. int[] intArray = new int[10000];
  49. for (int i=0; i<10000; i++) {
  50. intArray[i] = i+1;
  51. }
  52.  
  53. for (int i=0; i<10000; i++) {
  54. intArray[i] = i+1;
  55. }
  56.  
  57. for (int i=1; i=<10000; i++) {
  58. intArray[i] = i;
  59. }
  60.  
  61. int maxIndex = 0;
  62. for(int k = 1; k < intArray.length; k++)
  63. if(intArray[k] > intArray[maxIndex])
  64. maxIndex = k;
Add Comment
Please, Sign In to add comment