| Author |
Recursion and MergeSort : How is it working ?
|
Ashish Maharaja Singh
Greenhorn
Joined: Jun 06, 2011
Posts: 8
|
|
I am making a program to do MergeSort. It is not ready yet. Here is the test code which can split an array into half - works properly.
But I dont understand how it works - can someone explain this in terms of Stacks etc ?
Please let me know if my way is good or not.
What i am trying :
MyArray class has an int array called FULL. It stores the Left and Right halves of FULL in its Lt and Rt variables respectively.
It takes the array to be sorted and splits it into halves till array of size 1 is obtained. We (should) store the bottom-most array reference so
that we can go upwards (by using the MyArray "above" variable) and do the sorting.
|
 |
Ashish Schottky
Ranch Hand
Joined: Dec 29, 2009
Posts: 93
|
|
You can go here: to check how merge sort works and how it is implemented:
Programing AI
|
 |
Ashish Maharaja Singh
Greenhorn
Joined: Jun 06, 2011
Posts: 8
|
|
Ashish Schottky wrote:You can go here: to check how merge sort works and how it is implemented:
Programing AI
Thanks for the link. I prefer to do it myself. If there are any serious flaws in my approach, please let me know.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
Pencil, paper and a large eraser. That is what you need. You need to write down exactly how you intend to implement the splitting part of the algorithm, and how you stop when your divided arrays are 1 element long. Then you need to write down how to implement the merging part. When you have got it down to words of one syllable, you can convert your instructions into code quite easily.
I would suggest some more links about sorting: 1 2 3.
|
 |
Ashish Maharaja Singh
Greenhorn
Joined: Jun 06, 2011
Posts: 8
|
|
Campbell Ritchie wrote:Pencil, paper and a large eraser. That is what you need. You need to write down exactly how you intend to implement the splitting part of the algorithm, and how you stop when your divided arrays are 1 element long. Then you need to write down how to implement the merging part. When you have got it down to words of one syllable, you can convert your instructions into code quite easily.
I would suggest some more links about sorting: 1 2 3.
Thanks for the links. I am trying this again. Lots of paper in the bin already
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
You're supposed to rub out your errors, saving you throwing lots of paper away.
Or maybe the paper is where you wrote down your comments and opinions
|
 |
 |
|
|
subject: Recursion and MergeSort : How is it working ?
|
|
|