I need help witht his question for Java we cant use merge sorts and etc For an a
ID: 3885425 • Letter: I
Question
I need help witht his question for Java
we cant use merge sorts and etc
For an array where x>1
i need to find the middle, and then for the left part of the array i need to reverse every two consecutive values
for the right part i need to to do sometihng like this: i need to add the two values of every consecutive element and change the second element to what it adds up to for ex
"If the right half starts at index 13, and the values at index 13 & 14 are 73 and 11, then the value at index 14 is changed to 84."
just the psuedo code will be enough thanks
Explanation / Answer
PSEUDO CODE::
int [ ] a; // a is an integer array
int lower = 0; // lower is the lower index of the array
int upper = a.length-1; //upper is the upper index of the array
int middle = (lower + upper)/2;
//For left part
for(int i = 0; i < middle; i = i+2)
{
int temp = a[i];
a[i] = a[i+1];
a[i+1] = temp;
}
//For right part
for(int j = middle+1; j<upper; j = j+2)
{
a[j+1] = a[j] + a[j+1];
}