Skip to content

Commit

Permalink
Create Combosort.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
AnupamaTK committed May 12, 2021
1 parent 38f2ee8 commit f73de70
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Cpp/Combosort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include<bits/stdc++.h>
using namespace std;

int Comb_Sort(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;
}

0 comments on commit f73de70

Please sign in to comment.