정렬부분 도와주세요...
감춰왔던
질문 제목 : 정렬부분 도와주세요... 기존 head값을 이용하여 비교 후 head값을 복사한 headtemp에 정렬리스트 구현 후 출력, 그리고 메모리 free
질문 내용 :
프로그램 초기 구동시 파일값들을 읽어서 이중연결리스트로 구성하였습니다.
파일 내용은 이름, 나이, 성적 입니다.
ex) 1 1 1
3 3 3
2 2 2
이것을 출력시에 점수기준 오름차순으로 정렬을 하였습니다.
하지만 head값을 가지고 정렬을 해버려서 ㅡ; 리스트값이 변하는 상황이..그래서 head값을 복사할 구조체를 생성하여 그 복사한 값으로 점수기준 오름차순 출력을 해야하는데
도통 안되네요...
있는내공 다 걸겠습니다 도와주세요 ㅠㅠ
------------------------구조체
typedef struct maje{
char sname[20];
char sage[10];
char sscore[10];
struct maje *r;
struct maje *l;
}maje;
----------------------------------- 헤더파일 동적메모리 할당 함수
//headtemp가 출력 정렬담당할 임시저장 헤더잆니다...
void setmaje(void)
{
head = (maje *)malloc(sizeof(maje));
headtemp = (maje *)malloc(sizeof(maje));
head-r = null;
head-l = null;
headtemp-r = null;
headtemp-l = null;
}
-------------------------초기구동시 파일값 구조체에 리스트화 시키는 함수
void setfmaje(void)
{
sfiler();
maje *newdata, *cur, *temp;
cur = head;
while(!feof(fp))
{
newdata = (maje *)malloc(sizeof(maje));
if(fscanf(fp, %s %s %s, newdata-sname, newdata-sage, newdata-sscore) == -1)
{
free(newdata);
newdata = null;
break;
}
newdata-r = null;
newdata-l = null;
if(cur== null)
{
head-r = newdata;
cur = newdata;
}
else
{
while(cur && cur-r)
{
cur = cur-r;
&nbsbsp; }
cur-r = newdata;
newdata-l = cur;
newdata-r = null;
}
}
fclose(fp);
}
-----------------출력
void soutput(void)
{
maje *shead = head-r;
maje *sr = shead-r;
maje *htemp;
maje *stemp;
htemp = headtemp;
stemp = (maje *)malloc(sizeof(maje));
for(; shead-r != null; shead = shead-r)
{
for(sr = shead-r; sr; sr = sr-r)
{
if(atoi(shead-sscore) atoi(sr-sscore))
{
stemp = sr;
}
}
htemp-r = stemp;
stemp-r = null;
}
while(htemp-r != null)
{
printf(사원 이름 : %s\n, htemp-sname);
printf(사원 나이 : %s\n, htemp-sage);
printf(사원 점수 : %s\n\n, htemp-sscore);
htemp = htemp-r;
}
htemp = htemp-r;
while(htemp-r != null)
{
free(htemp-r);
htemp = htemp-r;
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |
2691450 | [visual c++ 툴]기초 질문 (3) | 해긴 | 2025-04-13 |