Can someone help me with the follow:

How would you implement mergesort without using recursion?

Recommended Answers

Are you sure that Daniweb is better than Goodge to search in INET?
http://www.algorithmist.com/index.php/Merge_sort.c

Jump to Post

All 7 Replies

Then why did you post anything?

The same question to you ;)
The only difference: I know what's your answer...

This is what I have so far, I need to know if I am on the right track:

Function Mergesort (field, lower, upper)
if lower = upper then do nothing (field is sorted)
else
middle = (upper + lower)/2
Mergesort (field, lower, middle)
Mergesort (field, middle+1, upper)
Merge (field, lower, middle, upper)
return field


Function Merge (field, lower, middle, upper)
Let ileft = lower, iright = middle+1, ihelp = lower
While ileft ≤ middle AND iright ≤ upper do
if field[ileft] ≤ field[iright] then
ifield[ihelp] = field
increment ihelp, increment iright
While ileft ≤ middle do
ifield[ihelp] = field[ileft]
increment ihelp, increment ileft
While iright ≤ upper do
ifield[ihelp] = field[iright]
increment ihelp, increment iright
For ihelp from lower to upper do
field[ihelp] = ifield[ihelp]
return field

Is there anyone that can assist me with this question?

Trying writing it out and posting it in code tags, so it keeps indenting until then it's almost unreadable.

And i would be guesing way to much

Chris

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.