링크드 리스트 소스관련 질문입니다..
레온
질문 제목 :링크드 리스트 소스관련 질문입니다..
질문 요약 :링크드 리스트 정확한 개념이해가 힘듭니다..
질문 내용 :
#include stdio.h
#include malloc.h
struct node {
int data;
struct node *next;
};
void main()
struct node *head;
struct node *nodeptr;
static int i=4;
head =(struct node*)malloc(sizeof(struct node));
head-data = 5;
head-next = NULL;
do{
// static int i=4; ----- 이부분이 에러나서 위로 올렸습니다.
nodeptr =(struct node*)malloc(sizeof(struct node));
nodeptr-data = i--;
nodeptr-next = head;
head=nodeptr;
}while(i1);
nodeptr=head-next; ---- 맨밑에 이 3줄도 이해가 잘안갑니다.
nodeptr-next-next-data=10;
head-data=nodeptr-data+5;
문제가 이렇게 주어지고 출력을
head - 3 - 2 - 1 - null -- 요렇게 출력하랍니다..
근데 제가 링크드 리스트 그림을 그려보고 저 do~while 문을 아무리 그려봐도 head 의 링크드 리스트가
이상하게 됩니다.
1. 저대로 돌리면 원래 head 값인 5 / null 값이 그냥 날라가고 data 값만 4 - 3 - 2 하고 반복문이 끝나는게 이상합니다.
2. 맨 밑에 3줄... 출력값과 무슨관계인지 전혀 이해가 가질 않습니다.
3. 부탁드립니다 C언어 고수님들 ㅜㅜ 설명과 함께 해답 출력 소스좀 부탁드립니다,
-
희미햬
링크드 리스트를 통하여 나타내려는게 무엇 인가요?