Write a function that computes and returns the score for a permutation, i.e. the number of reversals required to make arr[0] == 1.
HAVE TO USE FOLLOWING FORMAT:
Code:
// POST: Returns the number of reversals needed to make arr[0] == 1
// if the reversal game were played on arr
// Note: If arr[0] == 1 initially, then score(arr, n) returns 0
AND this is what i could muster;
Code:
int score(int arr[], int n)
{
int lo,hi;
for(lo=0,hi=size-1;lo<hi;lo++,hi--){
int temp=arr[lo];
arr[lo]=arr[hi];
arr[hi]=temp;}
return score;
}
Any help please.
Thank you.