-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathordination_methods.c
72 lines (64 loc) · 1.79 KB
/
ordination_methods.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <time.h>
#include "src/functions.h"
int main(){
// Variables declaration
int count_rows_file = 0;
float values_to_ordenate[150];
time_t time_start, time_end;
// Start execution time
time_start = time(NULL);
// Opening file and put into array
FILE *file;
if((file = fopen("values_to_ordinate.txt", "r")) == NULL) {
printf("It's no possible to open the file\n");
exit(1);
} else {
while(!feof(file)) {
fscanf(file, "%f", &values_to_ordenate[count_rows_file]);
count_rows_file++;
}
fclose(file);
}
// Menu to select sort method
printf("\n Sort Methods\n 1 - Seletion sort\n 2 - Insertion sort\n 3 - Shell sort\n 4 - Quick sort\n 5 - Merge sort\n Choose the option (only write the number and press enter): ");
int menu;
scanf("%d", &menu);
switch(menu){
case 1:
selection_sort_method(values_to_ordenate, count_rows_file);
break;
case 2:
insertion_sort_method(values_to_ordenate, count_rows_file);
break;
case 3:
shell_sort_method(values_to_ordenate, count_rows_file);
break;
case 4:
quick_sort_method(values_to_ordenate, 1, count_rows_file);
break;
case 5:
merge_sort_method(values_to_ordenate, 1, count_rows_file, count_rows_file);
break;
default:
printf("Invalid option. Choose again: ");
scanf("%d", &menu);
}
time_end = time(NULL);
// Wrinting a output file
file=fopen("output_file.txt", "w");
if(file == NULL){
printf("It's no possible to open the file\n");
exit(1);
}
for(int i = 1; i < count_rows_file; i++){
if(values_to_ordenate[i] > 0.00){
fprintf(file, "%.2f\n", values_to_ordenate[i]);
}
}
fclose(file);
printf("\n File was gerated with success\n");
exit(1);
}