Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Merge_sort

def mergeSort(arr):
    if len(arr) > 1:
        mid = len(arr)//2
        L = arr[:mid]
        R = arr[mid:]
        mergeSort(L)
        mergeSort(R)
        i = j = k = 0
        while i < len(L) and j < len(R):
            if L[i] < R[j]:
                arr[k] = L[i]
                i += 1
            else:
                arr[k] = R[j]
                j += 1
            k += 1
        while i < len(L):
            arr[k] = L[i]
            i += 1
            k += 1
        while j < len(R):
            arr[k] = R[j]
            j += 1
            k += 1
def printList(arr):
    for i in range(len(arr)):
        print(arr[i], end=" ")
    print()
if __name__ == '__main__':
    arr = [12, 11, 13, 5, 6, 7]
    print("Given array is", end="
")
    printList(arr)
    mergeSort(arr)
    print("Sorted array is: ", end="
")
    printList(arr)
Comment

PREVIOUS NEXT
Code Example
Python :: handdle close window action in pyqt5 
Python :: how to capture multiple screens with ImageGrab 
Python :: Allow Complex Number like "1+2j" to be treated as valid number 
Python :: mumtiply to matrices python 
Python :: non preemptive priority scheduling in c# 
Python :: django wht post save signal not firing 
Python :: how to convert hash to string in python 
Python :: Loop per n (batch) 
Python :: compute slice distance from image position 
Python :: new line in jupyter notebook markdown 
Python :: permcheck codility python 
Python :: Python Key Gen 
Python :: Get timestamp with pyrhon 
Python :: return tuples form functions in Python 
Python :: slug in redirect django 
Python :: python plot auc 95% confidence intervals stackoverflow 
Python :: how to get the remainder of a number when dividing in python 
Python :: grepper how to use fraction 
Python :: arm str example 
Python :: python setattr function 
Python :: ipython list command history 
Python :: loops with variables that count 
Python :: relation api profile does not exist django 
Python :: how to make an app like word in python 
Python :: Define a python function day_of_week, which displays the day name for a given date supplied in the form (day,month,year). 
Python :: install wget in anaconda 
Python :: simple example of printing a C version of a SymPy expression: 
Python :: pandas df where 
Python :: how to open an application in python 
Python :: python set console title 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =