Hi,

the following code is adopted PseudoCode from Introduction to

Algorithms (Cormen et al). For some reason it can't get it to work. I

always get a index of out bounds exception or some weird result.

Secondly I'd like to know how to write this more pythonic. TIA.

import random

import listutil

import unittest

def merge(A, p, q, r):

L = A[p:q]

R = A[q+1:r]

L.append(1001)

R.append(1001)

i=0

j=0

k=p

for k in range(r-p+1):

if L[i] <= R[j]:

A[k] = L[i]

i +=1

else:

A[k] = R[j]

j +=1

def mergeSort(A,p,r):

if p < r:

q=(p+r)/2

mergeSort(A,p,q)

mergeSort(A,q+1,r)

merge(A,p,q,r)