diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..1fa2cd0 Binary files /dev/null and b/.DS_Store differ diff --git a/quick_sort/data.txt b/quick_sort/data.txt new file mode 100644 index 0000000..09ef089 --- /dev/null +++ b/quick_sort/data.txt @@ -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 \ No newline at end of file diff --git a/quick_sort/quick_sort b/quick_sort/quick_sort index 115e6ad..fee08c7 100755 Binary files a/quick_sort/quick_sort and b/quick_sort/quick_sort differ diff --git a/quick_sort/quick_sort.c b/quick_sort/quick_sort.c index b3fa1ab..a82203e 100644 --- a/quick_sort/quick_sort.c +++ b/quick_sort/quick_sort.c @@ -1,4 +1,5 @@ #include +#include int swap( @@ -69,6 +70,7 @@ int right // 右端(※配列の要素数ではない) int main() { + /* int array[] = { 10, 20, 30, 50, 50, 10, 45, 65, @@ -79,6 +81,42 @@ main() 75, 15, 161, 165, 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);