Kent Beck
Сортировки
Класификация
Стабилност
struct human_t h1 = { 20, “Pesho” };
struct human_t h2 = { 20, “Gosho” };
struct human_t h3 = { 10, “Tosho” };
struct human_t people[3] = { h1, h2, h3 };
stable_sort(people); // h3, h1, h2
unstable_sort(people); // h3, h2, h1 или h3, h1, h2
Метод на мехурчето
Quicksort
Insertion sort
Упражнение: Insertion sort
i ← 1�while i < length(A)� j ← i� while j > 0 and A[j-1] > A[j]� swap A[j] and A[j-1]� j ← j - 1� end while� i ← i + 1�end while�
Shell sort
4 | 1 | 0 | 5 | 3 | 2 | 7 | 6 | 9 | 8 |
Shell sort
3-sorted
2-sorted
1-sorted
4 | 1 | 0 | 5 | 3 | 2 | 7 | 6 | 9 | 8 |
1 | 0 | 3 | 2 | 4 | 5 | 7 | 6 | 9 | 8 |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Shell sort
N - големина на масива�k - цяло число
Упражнение: Shell sort
Въпроси?