Sort
-
[Sort] Selection Sort (선택 정렬)Basic Programming/Algorithm 2018. 12. 11. 18:20
Selection Sort (선택 정렬) - Python - def selection_sort(collection): print('----- Selection Sort -----') print('input : ' + str(collection)) for i in range(len(collection)-1, 0, -1): pos_max = 0 for j in range (1, i+1): if collection[pos_max] < collection[j]: pos_max = j if(pos_max is not i): #if position is same, swap is unnecessary collection[pos_max], collection[i] = collection[i], collection[po..
-
[Sort] Insertion Sort (삽입 정렬)Basic Programming/Algorithm 2018. 12. 10. 18:49
Insertion Sort (삽입 정렬) - Python - def insertion_sort(collection): print('----- Insertion Sort -----') print('input : ' + str(collection)) for i in range(1, len(collection)): while 0 < i and collection[i] < collection[i-1]: collection[i], collection[i-1] = collection[i-1], collection[i] i = i - 1 print('progressing ... ' + str(collection)) return collection input = [3, 1, 6, 8, 4, 2, 9, 7, 10, 5]..
-
[Sort] Bubble Sort (버블 정렬, 거품 정렬)Basic Programming/Algorithm 2018. 12. 10. 18:42
Bubble sort (버블 정렬) Bubble sort is a basic sort algorithm.1. choose one object in the j(th) position in arraylist from the beginning.2. compare with the next object. If the chosen object is bigger than next object, swap objects. 3. Add one to j and increment to the end of the arraylist. Repeat this process until the end of arraylist.4. Repeat 1~3 process for length of array times. ** j (second l..