1. ## Merge Sort

Im working on this program, and Im trying to implement a merge sort, however, whenever I try it, the code seems to not work. I coded the exact pseudocode from this book I have so I dont know what the problem is.

Heres where my code is located at:

http://sourcepost.sytes.net/sourcepo...ource_id=24681

2. Originally Posted by osal
Im working on this program, and Im trying to implement a merge sort, however, whenever I try it, the code seems to not work.
What doesn't work about it? Can you be more specific? Doesn't compile? Gives wrong output? What?

P.S. (Is this really code written by you?)

3. >I coded the exact pseudocode from this book I have
What book? Who's the author? Books are often wrong when it comes to algorithms. And when the pseudocode is correct, it's very likely that a direct conversion to C or C++ will break because most pseudocode assumes that array indices start with 1.

4. Yes the code is written by me. This is the pseudocode of the merge sort:
this is the second function, the recursive function is correct i believe, however this is the pseudocode for the merge function. When I try to sort, it just prints the arrays as -8273439234 or some negative number.

MERGE(A,p,q,r)
n1 ← q - p +1
n2 ← r - q
create arrays L[1 ..n1 +1] and R[1 ..n2 +1]
for i ← 1 to n1
do L[i] ← A[p +i .1]
for j ← 1 to n2
do R[ j] ← A[q +j]
L[n1 +1] ← ∞
R[n2 +1] ← ∞
i ←1
j ←1
for k ← p to r
do if L[i] ≤ R[ j]
then A[k] ← L[i]
i ← i +1
else A[k] ← R[ j]
j ← j +1