/* 連結リストを表示する */ #include #include typedef struct node{ int data; struct node *next; } NODE, *Nodep; void displist(Nodep fp); Nodep first_p; /* 先頭ノードを指すポインタ */ main() { /* [1, 5, 9] というリストを作成 */ first_p = (Nodep)malloc(sizeof(NODE)); first_p->data = 1; first_p->next = (Nodep)malloc(sizeof(NODE)); first_p->next->data = 5; first_p->next->next = (Nodep)malloc(sizeof(NODE)); first_p->next->next->data = 9; first_p->next->next->next = NULL; displist(first_p); } void displist(Nodep fp) { printf("List"); if( fp == NULL ) { printf(" is empty\n"); return; } for( ; fp != NULL; fp = fp->next ) { printf("%5d", fp->data ); } printf("\n"); } /* end of llist1.c */