-
Notifications
You must be signed in to change notification settings - Fork 167
Expand file tree
/
Copy pathCombsort.cpp
More file actions
38 lines (29 loc) · 727 Bytes
/
Combsort.cpp
File metadata and controls
38 lines (29 loc) · 727 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
#include<bits/stdc++.h>
using namespace std;
int CombSort(int arr[], int n)
{
int gap = n;
while (gap != 1)
{
gap = int(gap/1.3);
if (gap < 1)
gap= 1;
for (int i=0; i<n-gap; i++)
{
if (arr[i] > arr[i+gap])
swap(arr[i], arr[i+gap]);
}
}
}
int main()
{
int arr[] = {121, 28, 332, -656, -841, 172, 236, 110, -28, 11, 574};
int n = sizeof(arr)/sizeof(arr[0]);
Comb_Sort(arr, n);
std::cout << "Input Array" << std::endl;
std::cout << "{121, 28, 332, -656, -841, 172, 236, 110, -28, 11, 574}"<< std::endl;
std::cout << "Sorted Array" << std::endl;
for (int i=0; i<n; i++)
std::cout << arr[i] <<" ";
return 0;
}