#include <stdio.h>
#include <stdlib.h>
struct list {
int val;
struct list *next;
};
void insert(struct list **pp, int val)
{
struct list *p;
p
= malloc(sizeof (struct list
)); p->val = val;
while (*pp) {
if ((*pp)->val >= val) break;
pp = &(*pp)->next;
}
p->next = *pp;
*pp = p;
}
int main()
{
struct list *p, *next, *head = NULL;
int val;
while (1) {
if (val < 0) break;
insert(&head, val);
}
for (p = head; p; p = next) {
next = p->next;
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnN0cnVjdCBsaXN0IHsKCWludAkJdmFsOwoJc3RydWN0IGxpc3QJKm5leHQ7Cn07Cgp2b2lkIGluc2VydChzdHJ1Y3QgbGlzdCAqKnBwLCBpbnQgdmFsKQp7CglzdHJ1Y3QgbGlzdCAqcDsKCglwID0gbWFsbG9jKHNpemVvZiAoc3RydWN0IGxpc3QpKTsKCXAtPnZhbCA9IHZhbDsKCXdoaWxlICgqcHApIHsKCQlpZiAoKCpwcCktPnZhbCA+PSB2YWwpIGJyZWFrOwoJCXBwID0gJigqcHApLT5uZXh0OwoJfQoJcC0+bmV4dCA9ICpwcDsKCSpwcCA9IHA7Cn0KCmludCBtYWluKCkKewoJc3RydWN0IGxpc3QgKnAsICpuZXh0LCAqaGVhZCA9IE5VTEw7CglpbnQgdmFsOwoKCXdoaWxlICgxKSB7CgkJc2NhbmYoIiVkIiwgJnZhbCk7CgkJaWYgKHZhbCA8IDApIGJyZWFrOwoJCWluc2VydCgmaGVhZCwgdmFsKTsKCX0KCWZvciAocCA9IGhlYWQ7IHA7IHAgPSBuZXh0KSB7CgkJcHJpbnRmKCIlZCAiLCBwLT52YWwpOwoJCW5leHQgPSBwLT5uZXh0OwoJCWZyZWUocCk7Cgl9CglwcmludGYoIlxuIik7CglyZXR1cm4gMDsKfQo=