Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool isOrdinato(int N, int V[])
- {
- bool isO = true;
- for(int i = 0; i < N-1; i++)
- {
- if(V[i] > V[i+1])
- return false;
- }
- return isO;
- }
- long long paletta_sort(int N, int V[]) {
- long long contatore = 0;
- int temp;
- int t1 = 0;
- bool t = true;
- for(int i = 0; i < N-2; i++)
- {
- t1++;
- if(V[i] > V[i+2])
- {
- contatore++;
- temp = V[i];
- V[i] = V[i+2];
- V[i+2] = temp;
- i-=3;
- if(i <-1)
- i=-1;
- }
- }
- t = isOrdinato(N,V);
- if(!t)
- return -1;
- if(t && contatore == 0)
- return 0;
- return contatore;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement