Anúncio

Ineed this in python- Thank you Modify the merge sort algorithm to sor.docx

rtodd972
28 de Jan de 2023
Ineed this in python- Thank you Modify the merge sort algorithm to sor.docx
Ineed this in python- Thank you Modify the merge sort algorithm to sor.docx
Próximos SlideShares
Introducing the central bank system of south Korea plz give lots of de.docxIntroducing the central bank system of south Korea plz give lots of de.docx
Carregando em ... 3
1 de 2
Anúncio

Mais conteúdo relacionado

Mais de rtodd972(20)

Anúncio

Ineed this in python- Thank you Modify the merge sort algorithm to sor.docx

  1. Ineed this in python. Thank you Modify the merge sort algorithm to sort a list in descending order. Solution #! /usr/bin/python def Merge(Array, firstStart, firstEnd, secondEnd): n1 = firstEnd - firstStart + 1 n2 = secondEnd = firstEnd Temp1 = [None] * n1 Temp2 = [None] * n2 for i in range(n1): Temp1[i] = Array[firstStart + i] for i in range(n2): Temp2[i] = Array[firstEnd + i + 1] i = 0 j = 0 for k in range(firstStart, secondEnd): if Temp1[i] >= Temp2[j]: Array[k] = Temp1[i] i = i + 1 else: Array[k] = Temp2[j] j = j + 1 return Array def MergeSort(Array, left, right): if left < right: mid = (left + right) / 2 MergeSort(Array, left, mid) MergeSort(Array, mid+1, right) Merge(Array, left, mid, right) Array  = [10, 30, 40, 80, 20, 70, 90, 60, 50]
  2. MergeSort(Array, 0, 8) print Array
Anúncio