/* Try 3 1 4 1 5. Draw some memory pictures. */ #include #include struct intlist { int data; struct intlist *next; } ; int main(void) { struct intlist head = { 0, 0 }; struct intlist *t; struct intlist *u; int n; while (scanf("%d",&n) == 1) { t = (struct intlist *) malloc(sizeof(struct intlist)); if (!t) { fprintf(stderr,"fatal: out of memory\n"); exit(1); } for (u = &head;u->next;u = u->next) if (u->next->data > n) break; t->data = n; t->next = u->next; u->next = t; } for (t = head.next;t;t = t->next) printf("%d\n",t->data); exit(0); }