-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathshellsort.c
38 lines (35 loc) · 882 Bytes
/
shellsort.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
/*
* Copyright(C) 2020, Bruno César Ribas <[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 "shellsort.h"
#include "ordenacaomacros.h"
static void insertionsortH(Item *v,int l,int r,int h)
{
for(int i=l+h;i<=r;i++)
{
int j=i; Item tmp=v[j];
while(j>=l+h && less(tmp,v[j-h]))
{
v[j]=v[j-h];
j-=h;
}
v[j]=tmp;
}
}
void shellsort(Item *v,int l,int r)
{
int h;
int t=(r-l)+1;
for(h=1;h<=(t-1)/9;h=3*h+1);
for(;h>0;h/=3)
insertionsortH(v,0,t-1,h);
}