링크드 리스트.........문제에요.ㅎ
민혁
질문 제목 : 질문 내용 :
밑에 밑줄 친것좀 알려주세요.ㅠㅠ 이해가 안되요.ㅠㅠ
그림으로 해주시면 더 감사하겠습니다.ㅠㅠ 링크드 리스트인데..ㅠㅠ 책봐도 이해가 안되네요.ㅎㅎ
#includestdio.h
typedef struct _node{int key;struct _node *next;}node;
node *head, *tail;
void init_list(void){head = (node*)malloc(sizeof(node));tail = (node*)malloc(sizeof(node));head-next = tail;tail-next = tail;}
int delete_next(node *t){node *s;if(t-next == tail)return 0;s = t-next;t-next = t-next-next;free(s);return 1;}
node *insert_after(int k, node *t){node *s;s=(node*)malloc(sizeof(node));s-key = k;s-next=t-next;t-next = s;return s;}
node *find_node(int k){node *s;s=head-next;while(s-key !=k && s!=tail)s=s-next;return s;}
int delete_node(int k){node *s;node *p;p = head;s = p-next;while(s-key !=k && s!=tail){p=p-next;s=p-next;}if(s!=tail){p-next = s-next;free(s);return 1;}elsereturn 0;}
node *insert_node(int t, int k){node *s;node *p;node *r;p=head;s=p-next;while(s-key !=k && s!=tail){p=p-next;s=p-next;}if(s !=tail){r=(node*)malloc(sizeof(node));r-key = t;p-next = r;r-next = s;}return p-next;}
node *ordered_insert(int k){node *s;node *p;node *r;p=head;s=p-next;while(s-key=k && s!=tail){p=p-next;s=p-next;}r=(node*)malloc(sizeof(node));r-key=k;p-next=r;r-next =s;return r;}
void print_list(node *t){printf(\n);while(t!=tail){printf(%-8d, t-key);t=t-next;}}
node *delete_all(void){node *s;node *t;t=head-next;while(t!=tail){s=t;t=t-next;free(s);}head-next=tail;return head;}
void mail(){node *t;
init_list();ordered_insert(10);ordered_insert(5);ordered_insert(8);ordered_insert(3);ordered_insert(1);ordered_insert(7);ordered_insert(8);
printf(\ninitial linked list is);print_list(head-next);
printf(\nfinding 4 is %ssuccessful, find_node(4) == tail?un:);
t=find_node(5);printf(\nfinding 5 is %ssuccessful, t==tail? un:);
printf(\ninserting 9 after 5);insert_after(9,t);print_list(head-next;
t=find_node(10);printf(\ndeleting next last node);delete_next(t);print_list(head-next);
t=find_node(3);printf(\ndeleting next 3);delete_next(t);print_list(head-next);
printf(\ninset node 2 before 3);inset_node(2,3);print_list(head-next);
printf(\ndeleting node 2);if(!delete_node(2))printf(\n deleting 2 is unsuccessful);print_list(head-next);
printf(\ndeleting node 1);delete_all();/div();print_list(head-next);}
-
봄해
아 알긴아는데 제가 저걸 그림으로 표현못하는거보니 다 이해햇다고 할순없겟죠 ㅠㅠ 머랄까 머릿속으로는 그림이 뱅뱅돌아 그려지는데 지면에 나타낼려니 안됩니다 ㅜㅠ
-
혁민
구조체와 포인터를 이해하지 못하면 링크드리스트를 이해할 수 없습니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2698120 | -연산자 가 먼지 좀 알려주세요 (1) | 낮선검객 | 2025-06-14 |
2698091 | 길찾기문제 질문이요! | 노을빛 | 2025-06-13 |
2698060 | while 문에 대한 질문입니다. (9) | 물고기자리 | 2025-06-13 |
2698012 | 2~9가아닌수 | 아놀드 | 2025-06-13 |
2697980 | for에 gets함수를 넣으니까 왜 반복이 안되죠 ㅜ (2) | 펴라 | 2025-06-12 |
2697952 | 2차배열과 함수문의^^; | VanilLa | 2025-06-12 |
2697924 | 다차원 배열 질문있습니다 | 두동 | 2025-06-12 |
2697893 | 정올 :: 기초다지기 a9007 배열7 (문제가 이상함 -_-) | 흰두루 | 2025-06-12 |
2697862 | Unable......... 지정된 파일을 찾을 수 없습니다!! (1) | Creator | 2025-06-11 |
2697761 | 그러니까여제말은... (2) | 새론 | 2025-06-10 |
2697737 | 정올 문제좀 풀어보신분~ | 레오 | 2025-06-10 |
2697709 | rand함수 질문좀요! (6) | 가막새 | 2025-06-10 |
2697683 | C언어 변수뒤 표시가 이해안되는게 있습니다. | 소미 | 2025-06-10 |
2697660 | 껍데기딜 만들고 난후 어느핫키 누르면 코드검색이라도 뜨고 그다음 무반응 해결좀 (2) | 움찬 | 2025-06-09 |
2697634 | c언어로 감성사전 만들기! (1) | 도란도란 | 2025-06-09 |
2697605 | 이 함수좀... | agine | 2025-06-09 |
2697574 | 배열 기본적인질문 (3) | 민트향 | 2025-06-09 |
2697549 | 배열 초기화 (4) | 나리 | 2025-06-08 |
2697465 | 수다님...^^ (2) | 가론 | 2025-06-08 |
2697432 | 서버 만드는 함수에서 궁금한게있어요~ | 파랑 | 2025-06-07 |