#include #include typedef struct list { char *word; struct list *next; } *LIST; LIST create(char *x) { LIST q; q = malloc(sizeof *q); q->word = x; q->next = NULL; return q; } LIST append(char *x, LIST p) { LIST q; q = malloc(sizeof *q); p->next = q; q->word = x; q->next = NULL; return q; } LIST insert(char *x, LIST p, int i) { LIST q; q = malloc(sizeof *q); while(i>0) { p = p->next; i--; } q->next = p->next; q->word = x; p->next = q; } void show_list(LIST p) { while (p != NULL) { printf("%s\n", p->word); p = p->next; } } main() { char *words[] = {"abc", "ghi", "xyz"}; char *word = "def"; int i; LIST p,q; p = q = create(words[0]); for(i=1; i<3; i++) { q = append(words[i], q); } insert(word, p, 0); /* 0番目の次に挿入 */ show_list(p); }