구조체와 포인터 오류좀 봐주세요 ...
휘들램
질문 제목 : 구조체 멤버변수들을 포인터를 이용(배열 사용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
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2695010 | C++의 STL은 왜 굳이 템플릿화 시켜서 라이브러리를 만드나요? (초보수준의 질문..) (2) | 엘보어 | 2025-05-16 |
2694958 | 로직이 변한다는 것에 대해서 궁금합니다. | 튼동 | 2025-05-16 |
2694929 | 열혈강의 25-2 두번째 문제 질문 | 지우개 | 2025-05-15 |
2694900 | dequeue 에서 리턴값 프린트 방법알려주세요 오늘 12시까지 대화방에 있습니다 도와주세요 | 미투리 | 2025-05-15 |
2694854 | 절대값을 구할때 (2) | 그녀는귀여웠다 | 2025-05-15 |
2694827 | 이제 어떻게 공부해야할지 모르겠네요 | 새얀 | 2025-05-14 |
2694778 | 순열 계산요. | 맛조이 | 2025-05-14 |
2694754 | ShowWindow 함수를 이용하려 하는데 질문있습니다. (2) | 파도 | 2025-05-14 |
2694731 | 리눅스 커널의 시작점 질문 | 미르 | 2025-05-13 |
2694702 | 이거 뭐가문제인가요 코드수정좀 (3) | 맑은 | 2025-05-13 |
2694675 | C언어 후위표기를 중위표기로 | 앨런 | 2025-05-13 |
2694646 | 안녕하세요 파일 합치기 함수! (1) | 연블루 | 2025-05-13 |
2694618 | 잘몰라서 설명부탁드립니다. scanf 관련 (3) | 파라 | 2025-05-12 |
2694590 | 이 코드가 뭐하는 코드일까요? #2 | 빵순 | 2025-05-12 |
2694559 | 동적할당으로 배열(2차원열)을 만드는데 있어 그걸 함수화시키는데... (1) | 늘솔길 | 2025-05-12 |
2694532 | 네트워크에 관하여... (4) | 황소자리 | 2025-05-12 |
2694503 | 프로그램 연산 후 바로 종료되는 현상 (6) | Judicious | 2025-05-11 |
2694450 | while문질문입니다. (1) | 허리품 | 2025-05-11 |
2694420 | C언어 질문할게요(유니코드,자료형,버퍼,캐스트연산자) | 은새 | 2025-05-11 |
2694370 | 내일까진데 함수호출 제발 도와주세요!!!!!!!!!11 | 들찬 | 2025-05-10 |