Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. // M - Main Array
  2. int Aindex = 0;
  3. int Bindex = 0;
  4. int A[] = new int[(int) (M.length + 1) / 2];
  5. int B[] = new int[(int) M.length / 2];
  6. while (!sakartotsAugosi(M)) { // While not sorted Look below for this function.
  7. Aindex = 0;
  8. Bindex = 0;
  9. for (int Mindex = 0; Mindex < M.length; Mindex++) {
  10. if ((Mindex + 1) % 2 != 0) {
  11. A[Aindex] = M[Mindex];
  12. Aindex++;
  13. } else {
  14. B[Bindex] = M[Mindex];
  15. Bindex++;
  16. }
  17. }
  18.  
  19.  
  20. Aindex = 0;
  21. Bindex = 0;
  22. for (int Mindex = 0; Mindex < M.length; Mindex++) {
  23. if (Aindex == A.length) {
  24. M[Mindex] = B[Bindex];
  25. Bindex++;
  26. } else if (Bindex == B.length) {
  27. M[Mindex] = A[Aindex];
  28. Aindex++;
  29. } else if (A[Aindex] <= B[Bindex]) {
  30. M[Mindex] = A[Aindex];
  31. Aindex++;
  32. } else if (B[Bindex] <= A[Aindex]) {
  33. M[Mindex] = B[Bindex];
  34. Bindex++;
  35. }
  36. }
  37.  
  38. public boolean sakartotsAugosi(int M[]) {
  39. for (int i = 1; i < M.length; i++) {
  40. if (M[i - 1] > M[i]) {
  41. return false;
  42. }
  43. }
  44. return true;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement