Shell sort algorithm implementation.
More...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
|
void | show_data (int *arr, long len) |
| Helper function to print array values.
|
|
void | swap (int *a, int *b) |
| Swap two integer variables.
|
|
void | shell_sort (int *array, long LEN) |
| Shell sort algorithm.
|
|
int | main (int argc, char *argv[]) |
| Main function.
|
|
◆ main()
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Main function.
67{
68 int i;
69 long size = 500;
70 if (argc == 2)
71 size = atol(argv[1]);
72 else if (argc > 2)
73 fprintf(stderr, "Usage: ./shell_sort [number of values]\n");
74
75 int *array = (
int *)
malloc(size *
sizeof(
int));
77 double time_spent;
78
79 srand(time(NULL));
80 for (i = 0; i < size; i++)
81
82 array[i] = rand() %
range + 1;
83
85 clock_t t1 = clock();
87 clock_t t2 = clock();
88
89 printf("Data Sorted\n");
91
92 printf("Time spent sorting: %.4g s\n", (t2 - t1) / CLOCKS_PER_SEC);
93
95 return 0;
96}
void shell_sort(int *array, long LEN)
Shell sort algorithm.
Definition shell_sort2.c:41
void show_data(int *arr, long len)
Helper function to print array values.
Definition shell_sort2.c:16
#define malloc(bytes)
This macro replace the standard malloc function with malloc_dbg.
Definition malloc_dbg.h:18
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition malloc_dbg.h:26
Definition prime_factoriziation.c:25