posted 11 years ago
Dear friends,
I'm dumbfounded in this particular code snippet, I would like to know your opinion as to how do i fix the problem and also if the below Algorithm is correct.
Please do not post the solution, i dont need it. I want to develop my own solution, all i need is your advice on how do i mend this code.
Lets say there is an integer array with input {-300,1,21,-1,9,10,5}
I want the output as [-300,-1,1,21,10,9,5]
So i wrote the algorithm for it
1. Find the length of the Array and divide it by 2 and deduct 1 from it as array positions start from Zero. Assign this value in a variable called midPosition.
2. Sort the Array in increasing order from Array position Zero to midPosition
3. Sort the Array in decreasing order from midPosition till Array Length
4. Print the Sorted Array
So based on this rough algorithm i wrote the following code
So when i execute the above code, the output is
So as you can see, its not the correct output. Do advise me how do i correct it.
>