-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortUtils.cpp
75 lines (72 loc) · 2.3 KB
/
sortUtils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// Created by Islam on 23.02.2022.
//
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
/**
* Метод, который сортирует массив
*
* @param array массив
* @param choice_sort выбор режима сортировки
* @param length размерность
* @return строка с выбранной сортировкой
*/
std::string takeTheSort(int *array, int choice_sort, int length) {
std::string nameOfSort;
if (choice_sort == 1) {
selectionSort(array, length);
nameOfSort = "Selection Sort";
} else if (choice_sort == 2) {
bubbleSort(array, length);
nameOfSort = "Bubble Sort";
} else if (choice_sort == 3) {
bubbleSortIversonFirst(array, length);
nameOfSort = "Bubble Iverson 1";
} else if (choice_sort == 4) {
bubbleSortIversonSecond(array, length);
nameOfSort = "Bubble Iverson 2";
} else if (choice_sort == 5) {
defaultSortArray(array, length);
nameOfSort = "Insertion Sort";
} else if (choice_sort == 6) {
binarySortArray(array, length);
nameOfSort = "Binary Insertion Sort";
} else if (choice_sort == 7) {
countingSortArray(array, length);
nameOfSort = "Counting Sort";
} else if (choice_sort == 8) {
radixSort(array, length);
nameOfSort = "Radix Sort";
} else if (choice_sort == 9) {
mergePivot(array, 0, length - 1);
nameOfSort = "Merge Sort";
} else if (choice_sort == 10) {
hoareQuickSort(array, 0, length - 1);
nameOfSort = "QuickSort Hoare partition";
} else if (choice_sort == 11) {
lomutoQuickSort(array, 0, length - 1);
nameOfSort = "QuickSort Lomuto partition";
} else if (choice_sort == 12) {
startHeapSort(array, length);
nameOfSort = "HeapSort";
}
return nameOfSort;
}
/**
* Метод, который позволяет узнать, отсортирован ли массив или нет
*
* @param arr массив
* @param n размерность
* @return 1 или 0 аналог True/False
*/
int arraySortedOrNot(int *arr, int n) {
if (n == 1 || n == 0) {
return 1;
}
if (arr[n - 1] < arr[n - 2]) {
return 0;
}
return arraySortedOrNot(arr, n - 1);
}