구조체와 포인터 오류좀 봐주세요 ...
휘들램
질문 제목 : 구조체 멤버변수들을 포인터를 이용(배열 사용x)하여 정렬하는문제라고 생각됩니다.
질문 요약 :struct student *next;는struct변수의 다음 변수로 이동 하는것입니다.
포인터가 struct 변수의 주소 를 저장하고 struct 변수를 포인터를 이용해서 정렬합니다.
제가 해보긴 했으나 오류가 좀 나오는데 고치기가 어렵네요.
오류좀 봐주세요.
질문 내용 :
#include stdio.h
struct student {
int number;
char name[10];
double height;
struct student *next;
};
void bubblesort(struct student *current);
int main(void)
{
struct student s1={1, B,190.1,NULL};// 넘버,이름,키
struct student s2={4, A,161.2,NULL};
struct student s3={3, C,152.3,NULL};
struct student s4={2, E,173.4,NULL};
struct student s5={9, D,154.5,NULL};
struct student s6={6, F,175.6,NULL};
struct student s7={10, H,186.7,NULL};
struct student s8={8, G,186.8,NULL};
struct student s9={5, J,184.9,NULL};
struct student s10={7, I,183.1,NULL};
struct student *first =NULL;
struct student *current = NULL;
first = &s1;
s1.next =&s2;
s2.next =&s3;
s3.next =&s4;
s4.next =&s5;
s5.next =&s6;
s6.next =&s7;
s7.next =&s8;
s8.next =&s9;
s9.next =&s10;
s10.next = NULL;
current = first;
while(current != NULL)
{
printf(정렬전 학생 번호 =%d\n 이름 =%s\n 키=%lf\n,current-number, current-name ,current-height);
current = current-next;
}
bubblesort(current);
while(current != NULL)
{
printf(정렬후 학생 번호 =%d\n 이름 =%s\n 키=%lf\n,current-number, current-name ,current-height);
current = current-next;
}
}
void bubblesort(struct student *current)
{
int least,temp;
/* int* pnumber = &(current-number);
double* pheight = &(current-height);
char* pname = &(current-name); 오류를 없애는데 사용하려고 만들었으나 못써봄...*/
while(current-next != NULL)//current가 NULL이 될때까지 반복
{
for( &(current-number) != NULL)//s1~10.number값 정렬하는 포문
{
least = current-number;
if(least current-number )
{
temp = current-number;
current-number = least;
least = temp;
}
current = current-next;
}
for( &(current-height) != NULL)//s1~10.height값 정렬하는 포문
{
(double)least = current-height;
if(least current-height )
{
temp = current-number;
current-height = least;
least = temp;
}
current = current-next;
}
for( &(current-name) !=NULL)//s1~10.name값 정렬하는 포문
{
(char)least = current-name;
if(least current-name)
{
temp = current-number;
current-name = least;
least = temp;
}
current = current-next;
}
current = current-next;//while 증감문 s1~s10
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2655416 | 고수님들 도움이 절실합니다. (2) | 세리 | 2024-05-19 |
2655361 | 엔터 입력받을때까지 기다리는 getchar (1) | 큰모음 | 2024-05-19 |
2655328 | 함수에서 포인터 (3) | 모아 | 2024-05-18 |
2655299 | 아이콘바꾸는법..? | 소 | 2024-05-18 |
2655271 | scanf 입력받으면 쭉 실행되는.. (5) | ComeOn | 2024-05-18 |
2655184 | 이 세개 프로그램좀 해결해주실.... 고수님들???? (3) | 말달리자 | 2024-05-17 |
2655129 | 다차원 배열 원소들 주소계산하는거 질문이요~ | 터전 | 2024-05-17 |
2655103 | AVRstudio MoveAxis. MoveLine 함수질문 | 앨버트 | 2024-05-16 |
2655072 | 콘솔창의 위치와 크기를 정하고 싶습니다. | 딥레드 | 2024-05-16 |
2655044 | 자료구조랑 online judge site에 대해서 질문있습니다... (1) | 뽀송뽀송 | 2024-05-16 |
2655016 | 별찍기 문제 중 이해안되는 부분이 있어요... | 도전중 | 2024-05-16 |
2654986 | 입력받은 성적을 배열에 저장하기 (3) | 안녕나야 | 2024-05-15 |
2654959 | ===========-이런거 미리 지정하는법 (1) | 김자영 | 2024-05-15 |
2654930 | 도와주십시요 ㅜㅜ 자료구조 ㅜㅜ | 도널드 | 2024-05-15 |
2654881 | PID 모듈 검색 부분 질문합니다 . | 이름없음 | 2024-05-14 |
2654850 | 조건에 만족하는 다음 수를 찾고 싶습니다. | 초엘 | 2024-05-14 |
2654790 | 두파일간 byte단위 txt파일 복사 中 | 슬찬 | 2024-05-14 |
2654768 | 사전만들기 입니다. | 여우By | 2024-05-13 |
2654716 | c언어 고수님들 답좀적어주세요 급합니다 ㅠㅠ | 한말글 | 2024-05-13 |
2654688 | c언어 ㅠㅠ 너 무 어려 워요 ㅠ 도와주세요!! | 별빛 | 2024-05-13 |