• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Recursion and MergeSort : How is it working ?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can go here: to check how merge sort works and how it is implemented:
Programing AI
 
Ashish Maharaja Singh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic