#include #include #define NIL NULL typedef struct node* Nodeptr; typedef struct node { int data; Nodeptr next; /* struct node* next; */ } Node ; Nodeptr mknode (int data) { Nodeptr np; np = (Nodeptr) malloc (sizeof (Node)); /* sizeof (struct node) */ if (np != NULL) { np->data = data; np->next = NULL; } return np; } Nodeptr insert (Nodeptr *list, int data) { Nodeptr np; if ((np = mknode (data)) != NULL) { Nodeptr curr = NULL; Nodeptr prev = NULL; for (curr = *list; curr && (data < curr->data); curr = curr->next) prev = curr; np->next = curr; if (prev) prev->next = np; else *list = np; } return np; } void print (Nodeptr list) { for ( ; list; list = list->next) printf("%d ", list->data); printf("\n"); } void sort (void) { Nodeptr list = NIL; int i; while ((scanf ("%d", &i) != EOF)) { printf ("%d ", i); if ( !insert (&list, i)) break; } print (list); } void main (void) { sort(); }