3
I was trying to write the merge sort
in python on my own, but returned a list nothing to do with several repeated numbers. When checking the solution code online, I was left with doubts about how to create and pass values from one list to the other, follows how it is written in código correto:
# a variável m desse código representa meio da lista
# create two empty arrays L[0..nL] and R[0..nR]
L = [0] * (nL + 1)
R = [0] * (nR + 1)
# copy left half of arr in L[0..nL-1]
for i in range(0, nL):
L[i] = arr[l + i]
# copy right half of arr in R[0..nR-1]
for j in range(0, nR):
R[j] = arr[m + 1 + j]
Next as eu escrevi:
# criei duas listas vazias
R = []
L = []
# passei metade da lista original para L
for i in range(0, nL):
tmp = a[i]
L.append(tmp)
# a outra metade para R
for j in range(nR, end):
tmp = a[j]
R.append(tmp)
whereas nL
and nR
split the list in half, the way in which I wrote results in a list other than the correct code?
p s..:link to the correct code