Problem in Sorting an Array

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.
>

It looks like your sort for the upper section is slightly off, as it is only picking up 3 values, missing out the 10 and 5 from the original array. I'd suggest going through that bit with a debugger and seeing why it is happening that way.

Also as a style point, you might want to put spaces in the code, it makes it nicer to read. Indentation is fine, but each line seems very scrunched up without spaces.

Strange, why it does not compile for you, for it very well compiles and runs for me because only then i was able to post the output of it too...
Perhaps, you need to check if you copied and pasted it correctly or not!

Ashish Dutt wrote: Strange, why it does not compile for you, for it very well compiles and runs for me because only then i was able to post the output of it too...
Perhaps, you need to check if you copied and pasted it correctly or not!

No, the code displayed in your first post absolutely will not compile. So either the forum's formatting software messed it up, or else the code you provided is not the same code you ran:

I am absolutely sure it has something to do with the forum's formatting software.
Let me repost the code again. This reminds me that computers are still noob's, you just cant rely upon them. From this time onwards i would check my code after enclosing it in the code tags, as a precautionary measure.