Presentation is loading. Please wait.

Presentation is loading. Please wait.

head data link data link data link NULL a b c

Similar presentations


Presentation on theme: "head data link data link data link NULL a b c"— Presentation transcript:

1 head data link data link data link NULL a b c
Linked list에서 head pointer는 첫 번째 노드를 가리킴 head data link data link data link NULL a b c #include <stdio.h> typedef int element; typedef struct ListNode { element data; struct ListNode *link; } ListNode; int main(void) { ListNode *head=NULL; // head 는 주소만 가짐으로 이것으로 충분 ListNode *a,*b,*c; // a,b,c 는 data와 link를 갖음으로 malloc 필요 a = (ListNode *) malloc(sizeof(ListNode)); a->data = 1; insert_node(&head, NULL, a); b = (ListNode *) malloc(sizeof(ListNode)); b->data = 2; insert_node(&head, a, b); c = (ListNode *) malloc(sizeof(ListNode)); c->data = 3; insert_node(&head, b, c); } 결론, head 는 malloc 필요하지 않음


Download ppt "head data link data link data link NULL a b c"

Similar presentations


Ads by Google