Created
October 12, 2018 06:11
-
-
Save AntiKnot/2e04023e1de72f8be9ac080c58fb41ef to your computer and use it in GitHub Desktop.
InfatuatedStaidFraction created by siyuYan - https://repl.it/@siyuYan/InfatuatedStaidFraction
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 bubble_sort(numbers:list)->list: | |
| length = len(numbers) | |
| for i in range(length): | |
| for j in range(0,length-i-1): | |
| if numbers[j]>numbers[j+1]: | |
| numbers[j],numbers[j+1] = numbers[j+1],numbers[j] | |
| return numbers |
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 func(): | |
| x = 0 | |
| while x < 10: | |
| print(x) | |
| x = x + 1 |
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
| print('hello world!') |
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 insertion_sort(nums:list)->list: | |
| length = len(nums) | |
| for i in range(1,length): | |
| while nums[i]<nums[i-1]: | |
| nums[i],nums[i-1] = nums[i-1],nums[i] | |
| return nums |
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 larger(x,y): | |
| if (x>y): | |
| return x | |
| return y |
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 BubbleSort import bubble_sort | |
| from SelectionSort import selection_sort | |
| from InsertionSort import insertion_sort | |
| from ShellSort import shell_sort | |
| from MergeSort import merge_sort | |
| from MergeSort import merge | |
| from HelloNumbers import func | |
| from Larger import larger | |
| nums = [3,5,2,1] | |
| print('hello world!') | |
| print(bubble_sort(nums)) | |
| print(selection_sort(nums)) | |
| print(insertion_sort(nums)) | |
| print(shell_sort(nums)) | |
| # print(merge_sort(nums)) | |
| print(merge(nums,nums)) | |
| func() | |
| print(larger(-1,2)) | |
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 merge(left,right): | |
| ans = [] | |
| while left and right: | |
| if left[-1] <= right[-1]: | |
| ans.append(left.pop()) | |
| else: | |
| ans.append(right.pop()) | |
| while left: | |
| ans += left | |
| while right: | |
| ans += right | |
| return ans | |
| def merge_sort(nums:list)->list: | |
| length = len(nums) | |
| if length<2: | |
| return nums | |
| left = nums[:length//2] | |
| right = nums[length//2:] | |
| return merge(merge_sort(left),merge_sort(right)) |
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 swap(a,b): | |
| a,b=b,a | |
| return True | |
| def quick_sort(nums:list)->list: | |
| length = len(nums) | |
| if length<2: | |
| return nums | |
| return quick_sort(partition[0])+quick_sort(partition[1]) | |
| def partition(nums:list)->list: | |
| left = [] | |
| right = [] | |
| pivot = nums[0] | |
| for num in nums[1:]: | |
| if num<pivot: | |
| left.append(num) | |
| else: | |
| right.append(num) | |
| return left,right |
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 selection_sort(nums:list)->list: | |
| minimum = float('inf') | |
| length = len(nums) | |
| for i in range(length): | |
| for j in range(i,length): | |
| if nums[j]<=minimum: | |
| minimum = nums[j] | |
| index = j | |
| nums[i], nums[index] = nums[index], nums[i] | |
| return nums |
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 shell_sort(nums:list)->list: | |
| gap = 3 | |
| length = len(nums) | |
| for i in range(gap): | |
| for j in range(length): | |
| for k in range(gap,length): | |
| while nums[k]<=nums[k-gap]: | |
| nums[k],nums[k-gap] = nums[k-gap],nums[k] | |
| return nums |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sort