Skip to content

Commit cef21cc

Browse files
authored
Update shellSort.c
1 parent 1abb8b2 commit cef21cc

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

sorting/shellSort.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,66 @@
33
#include <time.h>
44

55
#define ELEMENT_NR 20
6-
#define ARRAY_LEN(x) (sizeof(x)/sizeof((x)[0]))
6+
#define ARRAY_LEN(x) (sizeof(x) / sizeof((x)[0]))
77
const char *notation = "Shell Sort Big O Notation:\
88
\n--> Best Case: O(n log(n)) \
99
\n--> Average Case: depends on gap sequence \
1010
\n--> Worst Case: O(n)";
1111

1212
void show_data(int arr[], int len)
1313
{
14-
int i;
14+
int i;
1515

16-
for (i = 0; i < len; i++)
17-
printf("%3d ", arr[i]);
18-
printf("\n");
16+
for (i = 0; i < len; i++)
17+
printf("%3d ", arr[i]);
18+
printf("\n");
1919
}
2020

2121
void swap(int *a, int *b)
2222
{
23-
int tmp;
23+
int tmp;
2424

25-
tmp = *a;
26-
*a = *b;
27-
*b = tmp;
25+
tmp = *a;
26+
*a = *b;
27+
*b = tmp;
2828
}
2929

3030
void shellSort(int array[], int len)
3131
{
32-
int i, j, gap;
32+
int i, j, gap;
3333

34-
for (gap = len / 2; gap > 0; gap = gap / 2)
35-
for (i = gap; i < len; i++)
36-
for (j = i - gap; j >= 0 && array[j] > array[j + gap]; j = j - gap)
37-
swap(&array[j], &array[j + gap]);
34+
for (gap = len / 2; gap > 0; gap = gap / 2)
35+
for (i = gap; i < len; i++)
36+
for (j = i - gap; j >= 0 && array[j] > array[j + gap]; j = j - gap)
37+
swap(&array[j], &array[j + gap]);
3838
}
3939

4040
int main(int argc, char *argv[])
4141
{
42-
int i;
43-
int array[ELEMENT_NR];
44-
int range = 500;
45-
int size;
46-
clock_t start, end;
47-
double time_spent;
42+
int i;
43+
int array[ELEMENT_NR];
44+
int range = 500;
45+
int size;
46+
clock_t start, end;
47+
double time_spent;
4848

49-
srand(time(NULL));
50-
for (i= 0; i < ELEMENT_NR; i++)
51-
array[i] = rand() % range + 1;
49+
srand(time(NULL));
50+
for (i = 0; i < ELEMENT_NR; i++)
51+
array[i] = rand() % range + 1;
5252

53-
size = ARRAY_LEN(array);
53+
size = ARRAY_LEN(array);
5454

55-
show_data(array, size);
56-
start = clock();
57-
shellSort(array, size);
58-
end = clock();
59-
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
55+
show_data(array, size);
56+
start = clock();
57+
shellSort(array, size);
58+
end = clock();
59+
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
6060

61-
printf("Data Sorted\n");
62-
show_data(array, size);
61+
printf("Data Sorted\n");
62+
show_data(array, size);
6363

64-
printf("%s\n", notation);
65-
printf("Time spent sorting: %f\n", time_spent);
64+
printf("%s\n", notation);
65+
printf("Time spent sorting: %f\n", time_spent);
6666

67-
return 0;
67+
return 0;
6868
}

0 commit comments

Comments
 (0)