-
Notifications
You must be signed in to change notification settings - Fork 15
/
combsort.c
43 lines (39 loc) · 905 Bytes
/
combsort.c
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
39
40
41
42
43
/*
* Copyright(C) 2022, André Macedo Rodrigues Alves <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#include "combsort.h"
#include "ordenacaomacros.h"
void combsort(Item *v,int l,int r)
{
int gap = r-l;
double shrink = 1.3;
int sorted = 0;
while(sorted == 0)
{
gap = gap/shrink;
if(gap < 1)
{
gap = 1;
sorted = 1;
}
int i = l;
while(i + gap <= r)
{
if(v[i] > v[i+gap])
{
exch(v[i], v[i + gap]);
sorted = 0;
}
i++;
}
}
}