Hello,
I got a pseudo code and there are a few things I don't quite understand :)
First of all, here is the code:
Code:
1 IterativeMergeSort (Array A, s, n)
2 step ← 1
3 while step ≤ n do
4 left ← 1
5 while left ≤ n − step do
6 middle ← left + step − 1
7 middle ← min (middle, n)
8 right ← left + 2*step − 1
9 right ← min (right, n)
10 merge (A, left, middle, right)
11 left ← left + 2*step
12 step ← step *2
My function looks like this:
Code:
void merge_sort(int* array, int first, int last)
Okay, first I thought that left and right (pseudo code) were equal to first and last (code). But seeing as the peudo code uses the n, which is definitely equal to my last, do I have to initialize left, middle and right?
However, if I do this (and the pseudo code also looks like this), then I don't use s/first. It just doesn't appear at all!
What most confuses me is "min". It appears to be a function that I call, but which function? What does "min" stand for? Anyone have an idea? For now I tried a few things and just left it out but my code doesn't work so I feel like maybe I shouldn't ignore those two lines. :/
Thank you for any tipps on where I am wrong! :)
Every other function is working so I feel like the problem is in my inability to read the pseudo code.