-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f1fbf1
commit e22cc6f
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import time | ||
|
||
|
||
# Start timer | ||
startTimer = time.perf_counter() | ||
startTimer2 = time.process_time() | ||
|
||
# Random numbers in a list | ||
theList = [None] | ||
|
||
# --- Merge Sort --- # | ||
sortedList = [] | ||
def mergeSort(array = []): | ||
# Get each side their vars | ||
leftSum = len(array) // 2 | ||
leftSide = array[0:leftSum] | ||
rightSide = array[leftSum:] | ||
|
||
sortedArray = [] | ||
|
||
# Register values as a functional list | ||
newRightSideList = [] | ||
newLeftSideList = [] | ||
for nl in leftSide: | ||
newLeftSideList.append(nl) | ||
for rl in rightSide: | ||
newRightSideList.append(rl) | ||
|
||
# Sort left side | ||
for l in range(len(newLeftSideList)): | ||
minValue = min(newLeftSideList) | ||
sortedArray.append(minValue) | ||
newLeftSideList.remove(minValue) | ||
|
||
# Sort right side | ||
for r in range(len(newRightSideList)): | ||
minValue = min(newRightSideList) | ||
sortedArray.append(minValue) | ||
newRightSideList.remove(minValue) | ||
|
||
# Sorted list | ||
# Finally, sort both sides using each sorted side (left and right) | ||
print(sorted(sortedArray)) | ||
|
||
mergeSort(theList) | ||
|
||
endTimer = time.perf_counter() | ||
endTimer2 = time.process_time() | ||
|
||
print(f"Task Finished In Performance: {endTimer - startTimer:0.8f}\nTask Finished In Process/CPU/Kernel + User Space: {endTimer2 - startTimer2:0.8f}") |