Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. package sample;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. int i = 0;
  8. int[] Array = {11, 2, 13, 4, 4, 6};
  9. isSorted(i, Array);
  10. }
  11.  
  12. public static void isSorted(int i, int[] Array)
  13. {
  14.  
  15. if(Array[i]>Array[i+1])
  16. {
  17. int[] Array2 = new int[Array.length];
  18. for(int b = 0; b < Array.length; b++)
  19. {
  20. Array2[b] = Array[b];
  21. }
  22. sort(i, Array[i], Array, Array2);
  23. // System.out.println("sort() ausführen");
  24. }
  25. else
  26. {
  27.  
  28. if(i==Array.length-2)
  29. {
  30. System.out.println("Liste ist sortiert: " + java.util.Arrays.toString(Array));
  31. }
  32. else
  33. {
  34. isSorted(i+1, Array);
  35. }
  36. }
  37. }
  38.  
  39. public static void sort(int pivot, int pivotn, int[] arr, int[] arr2)
  40. {
  41.  
  42. for(int i = 0; i<arr.length-pivot-1; i++)
  43. {
  44. if(arr[pivot]>arr[pivot+1+i])
  45. {
  46. //System.out.println(arr[pivot+i+1]);
  47. arr2[pivot+i]=arr2[pivot+1+i];
  48. arr2[pivot+1+i]=arr[pivot];
  49. }
  50.  
  51. }
  52.  
  53. isSorted(0, arr2);
  54. //System.out.println("Liste arr: " + java.util.Arrays.toString(arr));
  55. //System.out.println("Liste sortiert: " + java.util.Arrays.toString(arr2));
  56.  
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement