#include #include #define WORDLENGTH 20 #define NWORDS 100 int main() { struct item { char word[WORDLENGTH]; struct item *next; }; struct item x[NWORDS]; struct item *first=NULL; struct item *p,**ptr; char word[WORDLENGTH]; int in = 0; /* read all the words in */ while (scanf("%s",word) == 1) { ptr = &first; /* Find where to insert */ while ((p=*ptr) != NULL) { if (strcmp(p->word,word) > 0) break; ptr = &(p->next); } /* Add in correct position */ strcpy(x[in].word,word); x[in].next = p; *ptr = &(x[in++]); } /* Now print them out */ p = first; while (p!= NULL) { printf("%s\n",p->word); p = p->next; } return(0); }