-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomb_sort.cpp
More file actions
50 lines (42 loc) · 839 Bytes
/
comb_sort.cpp
File metadata and controls
50 lines (42 loc) · 839 Bytes
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
// Marta Dzięgielewska
// Comb sort
// 26.11.2019
#include <iostream>
#include <math.h>
#include <cstdlib>
#include <ctime>
using namespace std;
int nextgap(int gap){
gap = gap/1.3;
return gap;
}
void combsort(int a[], int n){
int gap = n;
int i;
bool swapped = true;
while (gap > 1 || swapped == true){
gap = nextgap(gap);
swapped = false;
for (i=0 ; i< n-gap;i++){
if(a[i]>a[i+gap]){
swap(a[i], a[i+gap]);
swapped = true;
} else if(a[i+gap]>(a[i])){
continue;
}
}
}
}
int main()
{
srand(time(NULL));
int n = 100;
int a[n];
int i;
combsort(a,n);
cout << "Oto twoje posortowana tablica:" << endl;
for (i=0; i<n; i++){
cout << a[i] << endl;
}
return 0;
}