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
| quicksort :: (Ord a) => [a] -> [a] | |
| quicksort [] = [] | |
| quicksort (x:xs) = | |
| let smallerSorted = quicksort [a | a <- xs, a <= x] | |
| biggerSorted = quicksort [a | a <- xs, a > x] | |
| in smallerSorted ++ [x] ++ biggerSorted |
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(data): | |
| length = len(data) | |
| for i in range(1, length): | |
| j = i | |
| while j > 0 and data[j] < data[j-1]: | |
| tmp = data[j-1] | |
| data[j - 1] = data[j] | |
| data[j] = tmp | |
| j -= 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
| def vector_rotation(str, pos): | |
| '''Transpose concept: (A.T B.T).T = (BA) ''' | |
| l_half = str[:pos][::-1] | |
| r_half = str[pos:][::-1] | |
| new_str = l_half + r_half | |
| return new_str[::-1] | |
| s = 'abcdefgh' | |
| print(vector_rotation(s, 2)) | |
| print(vector_rotation(s, 3)) |
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
| a = Array.from({length: 15}).map((_,i) => i) | |
| function binarySearch(arr, needle) | |
| { | |
| let begin = 0, end = arr.length - 1 | |
| while (begin <= end) { | |
| let mid = Math.floor((end - begin) / 2) + begin | |
| if (arr[mid] === needle) { | |
| return mid | |
| } else if (arr[mid] > needle) { |
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
| function insertionSort(data) | |
| { | |
| for(let i = 1; i < data.length; ++i) { | |
| let j = i | |
| while(j > 0 && data[j] < data[j - 1]) { | |
| let tmp = data[j] | |
| data[j] = data[j - 1] | |
| data[j - 1] = tmp | |
| j -- | |
| } |
NewerOlder