-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge_sort.c
53 lines (51 loc) · 1.54 KB
/
merge_sort.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
44
45
46
47
48
49
50
51
52
53
/**
* Copyright 2020 Ali Cherry <[email protected]>
* This file is part of Simple Parallel Algorithms (SPA).
*
* SPA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* SPA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SPA. If not, see <https://www.gnu.org/licenses/>.
*/
#include "utils/sort_utils.h"
#include "utils/read_utils.h"
#include "utils/print_utils.h"
int main(int argc, char **argv)
{
char *input;
int res;
int *arr;
int size;
if (argc != 2) {
printf("Sequential merge sort usage:\n"
"\t%s <input>\n", argv[0]);
return 1;
}
input = argv[1];
res = read_integers_from_file(input,
&arr, &size);
if (res != 0) {
fprintf(stderr, "cant read ints.\n");
return 1;
}
printf("Printing unsorted array of size %d:\n", size);
print_integers(arr, size);
res = merge_sort(arr, size);
if (res != 0) {
fprintf(stderr, "cant sort array: %d\n", res);
return 1;
}
printf("Printing sorted array:\n");
print_integers(arr, size);
printf("Freeing...\n");
free(arr);
return 0;
}