add: quick sort from file

This commit is contained in:
kemasama 2022-04-26 18:59:07 +09:00
parent c89b8ed91f
commit 00f061fa5b
4 changed files with 62 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

24
quick_sort/data.txt Normal file
View File

@ -0,0 +1,24 @@
151515
15151
5151
15676
54345
676543
234567
5432
123456
7809876
543
21
23487
65
65
456
100
99
301
314
156615
56215562
61562
61562615

Binary file not shown.

View File

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
int int
swap( swap(
@ -69,6 +70,7 @@ int right // 右端(※配列の要素数ではない)
int int
main() main()
{ {
/*
int array[] = { int array[] = {
10, 20, 30, 50, 10, 20, 30, 50,
50, 10, 45, 65, 50, 10, 45, 65,
@ -79,6 +81,42 @@ main()
75, 15, 161, 165, 75, 15, 161, 165,
166, 167, 87, 86 166, 167, 87, 86
}; };
*/
char dataFile[] = "data.txt";
FILE *fp = fopen(dataFile, "r");
if ( fp == NULL ) {
printf("file can not open.\n");
return -1;
}
fseek(fp, 0, SEEK_SET);
int line_count = 0;
int c;
while ( (c = fgetc(fp)) != EOF )
{
if ( c == '\n')
{
line_count++;
}
}
int array[line_count];
fseek(fp, 0, SEEK_SET);
int read_line_size = 512;
char read_line[read_line_size];
int j;
for ( j = 0 ; j < line_count ; j++ )
{
fgets(read_line, read_line_size, fp);
array[j] = atoi(read_line);
}
fclose(fp);
int length = sizeof(array) / sizeof(int); int length = sizeof(array) / sizeof(int);