diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2022-05-02 09:49:01 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2022-05-02 09:49:01 +0900 |
| commit | 8c7809d024e85d0a8acfb794a4db41b0e4bc13e6 (patch) | |
| tree | 25ac81bad7be415d7cf75457275f7161d79f9f10 /comparison/Python/dummy.py | |
| parent | 429543c748aaf81b2a4207318eb5a05259469b21 (diff) | |
| download | inpla-8c7809d024e85d0a8acfb794a4db41b0e4bc13e6.tar.gz inpla-8c7809d024e85d0a8acfb794a4db41b0e4bc13e6.zip | |
v0.8.2-1
Diffstat (limited to 'comparison/Python/dummy.py')
| -rw-r--r-- | comparison/Python/dummy.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/comparison/Python/dummy.py b/comparison/Python/dummy.py new file mode 100644 index 0000000..98c2206 --- /dev/null +++ b/comparison/Python/dummy.py @@ -0,0 +1,64 @@ +# Python program for implementation of MergeSort +# https://www.geeksforgeeks.org/merge-sort/ +import random + +def mergeSort(arr): + if len(arr) > 1: + + # Finding the mid of the array + mid = len(arr)//2 + + # Dividing the array elements + L = arr[:mid] + + # into 2 halves + R = arr[mid:] + + # Sorting the first half + mergeSort(L) + + # Sorting the second half + mergeSort(R) + + i = j = k = 0 + + # Copy data to temp arrays L[] and R[] + 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 + + # Checking if any element was left + 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 mkRandList ( n ): + a=[] + for i in range(1,n+1): + a.insert(0, random.randint(0,10000)) + return a + + +def validation(alist): + for i in range(len(alist)-1): + if (alist[i] > alist[i+1]): + return False + + return True + + +a = mkRandList(10) +mergeSort(a) +print(validation(a)) |
