Develop a sorting algorithm. Your sorting algorithm may only be an implementation of a the shellsort, mergesort, or quicksort. Your algorithm must use an array of integers of at least 20 different items.

Respuesta :

Answer:

Explanation:

The following function is created in Python and uses a mergesort algorithm implementation in order to sort a given array of integers which is passed as an argument. Once complete it returns the sorted array. This can then be printed in the main method as seen in the attached picture below.

def BrainlySort(arr):

   if len(arr) > 1:

       mid = len(arr) // 2 #First find the middle of the array

       # Divide the array into two sections

       left = arr[:mid]

       right = arr[mid:]

       #Sort each section seperately

       BrainlySort(left)

       BrainlySort(right)

       i = j = k = 0

       # Copy data to temp arrays left[] and right[]

       while i < len(left) and j < len(right):

           if left[i] < right[j]:

               arr[k] = left[i]

               i += 1

           else:

               arr[k] = right[j]

               j += 1

           k += 1

       #Make sure no elements are left in the array

       while i < len(left):

           arr[k] = left[i]

           i += 1

           k += 1

       while j < len(right):

           arr[k] = right[j]

           j += 1

           k += 1

Ver imagen sandlee09
ACCESS MORE