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