[수정좀했습니다]C언어 텍스트파일을 읽어와서 힙정렬을 하는코드입니다.
딸기맛사탕
질문 제목 : 안녕하세요 C언어 초보입니다. 이코드는 C언어 텍스트파일을 읽어와서 힙정렬을 하는코드입니다. 그런데 결과가 잘 안나오네요....질문 요약 :txt파일에는 한글로된 데이터들이 있고 이것을 힙정렬 하는것입니다. 빌드는되는데 결과가 안나오네요 ㅠㅠ 어디가 문제인지 알고싶네요 질문 내용 :
#include stdio.h
#define length 116
void Heapsort(char station[][255], int num);
void Print(char station[][255], int num);
int main(void){
FILE *file = fopen(heapData.txt, r);
if(file == NULL)
{
puts(File Open Error...);
}
else if(file != NULL)
{
char station[length][255];
int b;
for ( b=0 ; b 116 ; b++)
{
fgets(&station[b][255],length,file);
if(station[b][255] == 0)
break;
}
Print(station,b);
Heapsort(station,b);
Print(station,b);
}
fclose(file);
return 0;
}
void Swap( char *a, char*b )
{
char exp = *a;
*a = *b;
*b = exp;
}
void Downheap(char station[][255], int num, int k)
{
int downIndex;
if ( &station[2*k][255] == NULL)
return ;
else if ( &station[2*k+1][255] == NULL) downIndex = 2*k;
else
if ( &station[2*k][255] &station[2*k+1][255]) downIndex = 2*k;
else downIndex = (2*k)+1;
if(&station[downIndex][255]&station[k][255])
{
Swap(&station[downIndex][255],&station[k][255]);
Downheap(station,num,downIndex);
}
}
void Makeheap(char station[][255],int num )
{
int i ;
for ( i = num/2 ; i=1 ; i--)
{
Downheap(station ,num, i);
Print(station,num);
}
}
void Heapsort(char station[][255], int num)
{
int i ;
Makeheap(station ,num);
for (i = num; i1 ; i--)
{
Swap(&station[1][255], &station[i][255]);
Downheap(station, i-1 , 1);
Print(station,num);
}
}
void Print(char station[][255], int num)
{
int c;
for ( c = 0 ; c num ; c++)
{
printf(%s, &station[c][255]);
}
}