Rahul Sudip Bose wrote:I wonder why it works well till the last step.
Just luck. Try it with a larger and more unordered array as your input.
Any place that gives clear code with detailed explanations ??? (Giving up because my approaches are producing junk.)
I'm sure that a Google search would lead to all kinds of pages about sorting.
I though that algorithms are supposed to be fun, but its depressing, especially due to esoteric books like cormen.
Different people have different ideas about what is fun. I'm sure if you got up and went out into the street and asked the first 100 people you met whether designing a sorting algorithm would be fun, you would get at least 99 "No" answers.
(Which is also the reason I haven't spent any time looking at your code. I'm perfectly willing to help you out by asking questions to push you in the right direction, though.)