From 00f061fa5b0fc366db6217b60f8c7436b63bfebc Mon Sep 17 00:00:00 2001 From: kemasama Date: Tue, 26 Apr 2022 18:59:07 +0900 Subject: [PATCH] add: quick sort from file --- .DS_Store | Bin 0 -> 6148 bytes quick_sort/data.txt | 24 ++++++++++++++++++++++++ quick_sort/quick_sort | Bin 33671 -> 33943 bytes quick_sort/quick_sort.c | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 .DS_Store create mode 100644 quick_sort/data.txt diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1fa2cd0a94352cac2ac446f04c5cfc13dcc0e9ee GIT binary patch literal 6148 zcmeHK%}T>S5T0$TO)WwX3OxqA7OZV4h?h|73mDOZN^DHg(3sUGHHT8jSzpK}@p+ut z-HN64;6=pF!0b0WKUwxm*vSHb=uLtHfEoZ;sDyq)SpT9zvm>F#-<~kT8aH zDVrUCkpX&lTkr%E2;mmKygxrn9{ouA7=QC0qcBOE&392KmNquaR@tgr*Y3T{+;osm zlHOo^NwYI4BY$oW{PS>_d9|Hm8K;9V9*$K(7z{Dx>LQE-nf2r(4iZ)C>VQ?TDqgKV zowmBohTZOTXAOIL*h0J0?#^ZvYjv%E)UfEoA^19U#vsDzHeT%$TVaG>8uikApU(5AZt zp>5DHm}|rciqNHqx>T4ehS25cw@sd7FxRNdL8z7SIc8;HZYV;nj(%IEgK#wR$P6$8 ziwqR?v_}2^J2Ih<>eYbOVCiQ7;~u= c*HM+A-zEdmF_>#a4+{SXC>nTR27Z-+4->>r5dZ)H literal 0 HcmV?d00001 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_s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WPY$lro^BL$r4A*T>N5DkuFO}7a&;;OMOmzhm9xsopYY| zzUO)GJ@=gGF==Q>iWIV-R@BO-weA{b)JDr6E%p#GB1%Z;(270UAKsnw-dyyFT#$s; z6S5JLfmAVBmQ_T7z^>k&w?euSy5+^TmWPr`>vDdo9xCON%*lPsRd7mwQlLLM#Ru5$ z%*A&~B~0drr5b5S=HEzbDq~1kPoz39##EwB7{x0UgCw*G<9h={UEC-;nSs|EN{n65 zOSLV_d7E6}i21L)|D3(L>f4tO-2QOtl@O1})l#aKUzeN861qVpOhf@;DB3C@bP7gM zHdb$F-7w}etY>4fjnk|@Bg>Nueb&*1A0!RsFPn@?+QgLf#X;x1iPYw#o#L5tiYGoH zEn%fJ_Brx+(4$EX^~MIGVUqzlZi>&im3UG%e}+O43VO8}nY0Q<>8Fu%)2_r5RwbQ8 zj%1`a4`(vbjFaN<>Mu+>mF!{@Gw<6gQ44~FGfp+0L_zbRJzqaG{rErA5}0NSec{!x zcf(?h@G%*wAPM8yOlD>N$BYgJ=HWkkm2&?01!j6J&Skd!n@ z&Z+F&k~g>I<`z^f1gpV19T9sH)PqKVU7>1V2Wx;6*nl`4Via*JKn>dZJi6te9f-x7 zfk-$DE`U$L2xtYbfyU0BH$q(-U28imw6=ppZT@B5Dx0_hRS<%-m;YARAd$NGuTPjC zaUt#lJAi=~s14RKoMu#H+u-m~xZKv=*}W@xhyua=dwN2<`7O1!{~*aUExJ@6mc~I~moEy43-rG2$ c+`qLo)O_sHOC#Io+z;-h|2%Nz_!)cbUl|}M1ONa4 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);