mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-02-12 23:15:52 +08:00
formatting source-code for 153fb7b8a5
This commit is contained in:
@@ -8,15 +8,13 @@
|
||||
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;
|
||||
|
||||
@@ -24,18 +22,15 @@ 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;
|
||||
}
|
||||
@@ -43,8 +38,7 @@ 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