This file contains hidden or 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
| if __name__ == '__main__': | |
| from sys import argv | |
| from random import shuffle | |
| list = list(range(int(argv[1]))) | |
| list.sort() # ;) | |
| print(all(list[i] <= list[i+1] for i in range(len(list)-1))) | |
| # seriously though timsort is really weird |
This file contains hidden or 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
| def selectionsort(list): | |
| n = [] | |
| while len(list) > 1: | |
| n.append(list.pop(list.index(min(list)))) | |
| return n | |
| if __name__ == '__main__': | |
| from sys import argv | |
| from random import shuffle |
This file contains hidden or 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
| from random import randrange | |
| def qsort(list): | |
| if len(list) > 1: | |
| pivot = list.pop(randrange(0, len(list))) | |
| a = qsort([i for i in list if i < pivot]) | |
| b = qsort([i for i in list if i >= pivot]) | |
| return a + [pivot] + b | |
| else: | |
| return list |
This file contains hidden or 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
| def bubblesort(list): | |
| swapped = True | |
| while swapped: | |
| swapped = False | |
| for p in range(len(list)-1): | |
| if list[p] > list[p+1]: | |
| list[p] = list[p] ^ list[p+1] | |
| list[p+1] = list[p] ^ list[p+1] | |
| list[p] = list[p] ^ list[p+1] | |
| swapped = True |
This file contains hidden or 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
| def mergesort(c): | |
| if len(c) > 1: | |
| pivot = len(c)//2 | |
| a = c[:pivot] | |
| b = c[pivot:] | |
| mergesort(a) | |
| mergesort(b) | |
| ap = 0 | |
| bp = 0 | |
| cp = 0 |
NewerOlder