mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-15 11:20:05 +08:00
formatting source-code for d7af6fdc8c
This commit is contained in:
@@ -8,13 +8,15 @@
|
||||
int a[100005];
|
||||
int n;
|
||||
|
||||
int FindNextGap(int x) {
|
||||
int FindNextGap(int x)
|
||||
{
|
||||
x = (x * 10) / 13;
|
||||
|
||||
return std::max(1, x);
|
||||
}
|
||||
|
||||
void CombSort(int a[], int l, int r) {
|
||||
void CombSort(int a[], int l, int r)
|
||||
{
|
||||
// Init gap
|
||||
int gap = n;
|
||||
|
||||
@@ -22,15 +24,18 @@ void CombSort(int a[], int l, int r) {
|
||||
bool swapped = true;
|
||||
|
||||
// Keep running until gap = 1 or none elements were swapped
|
||||
while (gap != 1 || swapped) {
|
||||
while (gap != 1 || swapped)
|
||||
{
|
||||
// Find next gap
|
||||
gap = FindNextGap(gap);
|
||||
|
||||
swapped = false;
|
||||
|
||||
// Compare all elements with current gap
|
||||
for (int i = l; i <= r - gap; ++i) {
|
||||
if (a[i] > a[i + gap]) {
|
||||
for (int i = l; i <= r - gap; ++i)
|
||||
{
|
||||
if (a[i] > a[i + gap])
|
||||
{
|
||||
std::swap(a[i], a[i + gap]);
|
||||
swapped = true;
|
||||
}
|
||||
@@ -38,7 +43,8 @@ void CombSort(int a[], int l, int r) {
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
std::cin >> n;
|
||||
for (int i = 1; i <= n; ++i) std::cin >> a[i];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user