code: code clean
This commit is contained in:
parent
00f061fa5b
commit
511de8b71f
Binary file not shown.
@ -70,21 +70,16 @@ int right // 右端(※配列の要素数ではない)
|
|||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
/*
|
int i;
|
||||||
int array[] = {
|
int j;
|
||||||
10, 20, 30, 50,
|
int c;
|
||||||
50, 10, 45, 65,
|
int length = 0;
|
||||||
76, 54, 56, 15,
|
int read_line_size = 512;
|
||||||
34, 31, 14, 17,
|
char read_line[read_line_size];
|
||||||
14, 15, 11, 16,
|
FILE *fp;
|
||||||
90, 19, 98, 76,
|
|
||||||
75, 15, 161, 165,
|
|
||||||
166, 167, 87, 86
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
char dataFile[] = "data.txt";
|
char dataFile[] = "data.txt";
|
||||||
FILE *fp = fopen(dataFile, "r");
|
fp = fopen(dataFile, "r");
|
||||||
|
|
||||||
if ( fp == NULL ) {
|
if ( fp == NULL ) {
|
||||||
printf("file can not open.\n");
|
printf("file can not open.\n");
|
||||||
@ -92,25 +87,19 @@ main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
fseek(fp, 0, SEEK_SET);
|
fseek(fp, 0, SEEK_SET);
|
||||||
int line_count = 0;
|
|
||||||
int c;
|
|
||||||
while ( (c = fgetc(fp)) != EOF )
|
while ( (c = fgetc(fp)) != EOF )
|
||||||
{
|
{
|
||||||
if ( c == '\n')
|
if ( c == '\n')
|
||||||
{
|
{
|
||||||
line_count++;
|
length++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int array[line_count];
|
int array[length];
|
||||||
|
|
||||||
fseek(fp, 0, SEEK_SET);
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
|
||||||
int read_line_size = 512;
|
for ( j = 0 ; j < length ; j++ )
|
||||||
char read_line[read_line_size];
|
|
||||||
int j;
|
|
||||||
|
|
||||||
for ( j = 0 ; j < line_count ; j++ )
|
|
||||||
{
|
{
|
||||||
fgets(read_line, read_line_size, fp);
|
fgets(read_line, read_line_size, fp);
|
||||||
array[j] = atoi(read_line);
|
array[j] = atoi(read_line);
|
||||||
@ -118,12 +107,8 @@ main()
|
|||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
int length = sizeof(array) / sizeof(int);
|
|
||||||
|
|
||||||
printf("Length: %d\n", length);
|
printf("Length: %d\n", length);
|
||||||
quick_sort(array, 0, length - 1);
|
quick_sort(array, 0, length - 1);
|
||||||
|
|
||||||
int i ;
|
|
||||||
|
|
||||||
for ( i = 0 ; i < length ; i++ )
|
for ( i = 0 ; i < length ; i++ )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user