Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why noy combSort?

{
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;
}