1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <stdio.h> #include <stdlib.h> typedef struct node { int data; //나중에 void 로 사용해 받는 인자를 다양하게 할수있다. struct node *next; } Node; int main(void) { Node *p; p = (Node *)malloc(sizeof(Node)); //p = (Node *)malloc(sizeof(struct node)); p->data = 10; p->next=(Node *)malloc(sizeof(Node)); //p = (Node *)malloc(sizeof(struct node)); p->next->data = 20; p->next->next=(Node *)malloc(sizeof(Node)); p->next->next->data = 30; p->next->next->next=(Node *)malloc(sizeof(Node)); p->next->next->next->data = 40; p->next->next->next->next = NULL; for(Node *tmp = p; tmp != NULL; tmp=tmp->next) { printf("%d, " , tmp->data); } printf("\n"); return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <stdio.h> #include <stdlib.h> typedef struct node { int data; struct node *next; } Node; int main(void) { Node *p; p = (Node *)malloc(sizeof(Node)); p->data = 10; p->next=(Node *)malloc(sizeof(Node)); p->next->data = 20; p->next->next=(Node *)malloc(sizeof(Node)); p->next->next->data = 30; p->next->next->next=(Node *)malloc(sizeof(Node)); p->next->next->next->data = 40; p->next->next->next->next = NULL; //Insert tmp Node *tmp; tmp = (Node *)malloc(sizeof(Node)); tmp->data = 15; tmp->next = p->next; p->next = tmp; for(Node *tmp = p; tmp != NULL; tmp=tmp->next) { printf("%d, " , tmp->data); } printf("\n"); return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <stdio.h> #include <stdlib.h> typedef struct node { int data; struct node *next; } Node; int main(void) { Node *p; p = (Node *)malloc(sizeof(Node)); p->data = 10; p->next=(Node *)malloc(sizeof(Node)); p->next->data = 20; p->next->next=(Node *)malloc(sizeof(Node)); p->next->next->data = 30; p->next->next->next=(Node *)malloc(sizeof(Node)); p->next->next->next->data = 40; p->next->next->next->next = NULL; { //Incert tmp Node *tmp; tmp = (Node *)malloc(sizeof(Node)); tmp->data = 15; tmp->next = p->next; p->next = tmp; } { //delete Node *tmp, *del; tmp = p->next; del = tmp->next; tmp->next = tmp->next->next; free(del); } for(Node *tmp = p; tmp != NULL; tmp=tmp->next) { printf("%d, " , tmp->data); } printf("\n"); return 0; } |
한번에 출력
'Study > 리눅스' 카테고리의 다른 글
리눅스로 c언어 컴파일하기 Java (1) (0) | 2014.09.19 |
---|---|
리눅스로 c언어 컴파일하기 Linked List (2) (0) | 2014.09.19 |
리눅스로 c언어 컴파일하기 모듈사용하기 (1) (0) | 2014.09.18 |
리눅스 c언어로 컴파일하기 파일 입출력 (1) (0) | 2014.09.18 |
리눅스로 c언어 컴파일하기 arm-linux-gcc (1) (0) | 2014.09.18 |