Advertisement
Guest User

Untitled

a guest
May 29th, 2017
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1.  
  2. bool isOrdinato(int N, int V[])
  3. {
  4. bool isO = true;
  5.  
  6.  
  7. for(int i = 0; i < N-1; i++)
  8. {
  9. if(V[i] > V[i+1])
  10. return false;
  11. }
  12.  
  13. return isO;
  14. }
  15.  
  16. long long paletta_sort(int N, int V[]) {
  17.  
  18.  
  19.  
  20. long long contatore = 0;
  21. int temp;
  22. int t1 = 0;
  23.  
  24. bool t = true;
  25.  
  26. for(int i = 0; i < N-2; i++)
  27. {
  28. t1++;
  29.  
  30.  
  31. if(V[i] > V[i+2])
  32. {
  33. contatore++;
  34.  
  35. temp = V[i];
  36. V[i] = V[i+2];
  37. V[i+2] = temp;
  38.  
  39. i-=3;
  40.  
  41. if(i <-1)
  42. i=-1;
  43. }
  44.  
  45.  
  46. }
  47.  
  48. t = isOrdinato(N,V);
  49.  
  50. if(!t)
  51. return -1;
  52.  
  53. if(t && contatore == 0)
  54. return 0;
  55.  
  56. return contatore;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement