-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortingAlgorithms.cpp
More file actions
91 lines (69 loc) · 1.46 KB
/
sortingAlgorithms.cpp
File metadata and controls
91 lines (69 loc) · 1.46 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<bits/stdc++.h>
using namespace std;
class SortMe{
private:
vector<int> array;
void bubble_sort(vector<int>& arr){
int size = arr.size();
for(int i = 0; i < size; i ++){
for(int j = 0; j < size - i - 1; j ++){
if(arr[j] > arr[j + 1]){
swap(arr[j], arr[j + 1]);
}
}
}
}
void insertion_sort(vector<int>& arr){
int size = arr.size();
for(int i = 0; i < size; i ++){
int min = i;
for(int j = i + 1; j < size; j ++){
if(arr[j] < arr[min]){
min = j;
}
}
swap(arr[i], arr[min]);
}
}
void counting_sort(vector<int> &arr){
int size = arr.size();
vector<int> out(size);
// 0 <= arr[i] <= 1000
int count[1001];
int size = arr.size();
for(int i = 0; i < size; i ++){
count[arr[i]] ++;
}
for(int i = 1; i < 1001; i ++){
count[i] += count[i - 1];
}
for(int i = 0; i < size; i ++){
out[count[arr[i]] - 1] = arr[i];
count[arr[i]] --;
}
return out;
}
void like_normal_human(vetor<int>& arr){
sort(begin(arr), end(arr))
// or
sort(arr.begin(), arr.end());
}
public:
SortMe(){}
SortMe(vector<int> array){
this->array = array;
}
void bubble_sort(){
this->bubble_sort(this->array);
}
void insertion_sort(){
this->insertion_sort(this->array);
}
void counting_sort(){
this->counting_sort(this->array);
}
void like_normal_human(){
this->like_normal_human(this->array);
}
}
int main(){}