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

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 meeting, networking, learning, and sharing knowledge.