Can someone help me with the follow:

How would you implement mergesort without using recursion?

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

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

This article has been dead for over six months. Start a new discussion instead.