연결리스트 정렬 질문... ㅠㅠ
아쿠아리우스
질문 제목 : 질문 내용 :
ppt에 나온대로 만드는데요...정렬이 문제네요...
구주체..연결리스트로 만들어서...정렬을 하라는데. ㅠㅠ코드는 대충 짜봣습니다 ㅎ#include stdio.h
#include stdlib.h
#include string.htypedef struct _student
{
char name[100];
int sid;
char payed;
int numberofcourse;
struct course* cnext;
struct student* snext;
}student;typedef struct _course
{
char name[100];
char number[30];
int credithours;
char grade;
struct course* cnext;
}course;int main()
{
student *p = (student *)malloc(4*sizeof(student));
course *c = (course *)malloc(18*sizeof(course));
char buffer[100];
char line[30][32768];
file *fp = null;
char *token;
int i = 0,j=0,n=0,chk=0;
int st=0,k=0;
int line_count=0;
char s[] = ; fp = fopen(input.txt,rt);
while( fgets(buffer,100,fp) != null)
{
strcpy(line[i],buffer);
i++;
line_count++;
}
token = strtok(line[0],s);
while( j line_count )
{
while( token != null)
{
n++;
switch(n)
{
case 1:
strcpy((p+st)-name,token);
break;
case 2:
chk = atoi(token);
(p+st)-sid = chk;
break;
case 3:
(p+st)-payed = *token;
break;
case 4:
chk = atoi(token);
(p+st)-numberofcourse = chk;
break;
}
token = strtok(null,s);
} (p+st)-snext = (p+st+1);
(p+st+1)-snext = null;
n = 0;
for(i=0;i(p+st)-numberofcourse;i++,++j) // 과목수만큼 for문을 돈다
{
token = strtok(line[j+1],s);
while( token != null )
{
n++;
switch(n)
{
case 1:
strcpy((c+k)-name,token);
break;
case 2:
strcpy((c+k)-number,token);
break;
case 3:
chk = atoi(token);
(c+k)-credithours = chk;
break;
case 4:
(c+k)-grade = *token;
break;
}
token=strtok(null,s);
}
(p+st)-cnext = (c+k);
(c+k)-cnext = (c+k+1);
(c+k+1)-cnext = null;
k++;
n = 0;
}
st++;
j=j+2; // j에다가 1을 더하면 공백라인 1을 더더하면 다시 학생정보
token = strtok(line[j],s); // 학생정보를 나눈다.
} for(i=0;i4;i++)
printf(%s %d %c %d\n,(p+i)-name,(p+i)-sid,(p+i)-payed,(p+i)-numberofcourse);
for(i=0;i18;i++)
printf(%s %s %d %c\n,(c+i)-name,(c+i)-number,(c+i)-credithours,(c+i)-grade);
fclose(fp); //printf(출력할 방법을 선택하세요 (1. 이름순 2.학번순 3. 성적순) );
//scanf(%d,);
}