#include <stdio.h>
#include <stdlib.h>
typedef struct list {
struct list *m_pNext;
int m_value;
} List;
List *list_insert(List *pHead, int value)
{
List
*pNew
= malloc(sizeof(List
)); pNew->m_value = value;
pNew->m_pNext = pHead;
return pNew;
}
List *list_sorted_insert(List *pHead, int value)
{
List *p, *pPrev = NULL;
for (p = pHead; p; p = p->m_pNext) {
if (value <= p->m_value) {
break;
}
pPrev = p;
}
List *pNew = list_insert(p, value);
if (pPrev) {
pPrev->m_pNext = pNew;
} else {
pHead = pNew;
}
return pHead;
}
void list_print(List *pHead)
{
List *p;
for (p = pHead; p; p = p->m_pNext) {
}
}
void list_free(List *pHead)
{
List *p, *q;
for (p = pHead; p; p = q) {
q = p->m_pNext;
}
}
int main()
{
List *pHead = NULL;
int value;
for (; ;) {
if (scanf("%d", &value
) < 1) { continue;
}
if (value < 0) {
break;
}
pHead = list_sorted_insert(pHead, value);
}
list_print(pHead);
list_free(pHead);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnR5cGVkZWYgc3RydWN0IGxpc3QgewogICAgc3RydWN0IGxpc3QgKm1fcE5leHQ7CiAgICBpbnQgbV92YWx1ZTsKfSBMaXN0OwogCkxpc3QgKmxpc3RfaW5zZXJ0KExpc3QgKnBIZWFkLCBpbnQgdmFsdWUpCnsKICAgIExpc3QgKnBOZXcgPSBtYWxsb2Moc2l6ZW9mKExpc3QpKTsKICAgIHBOZXctPm1fdmFsdWUgPSB2YWx1ZTsKICAgIHBOZXctPm1fcE5leHQgPSBwSGVhZDsKICAgIAogICAgcmV0dXJuIHBOZXc7Cn0KCkxpc3QgKmxpc3Rfc29ydGVkX2luc2VydChMaXN0ICpwSGVhZCwgaW50IHZhbHVlKQp7CiAgICBMaXN0ICpwLCAqcFByZXYgPSBOVUxMOwogICAgCiAgICBmb3IgKHAgPSBwSGVhZDsgcDsgcCA9IHAtPm1fcE5leHQpIHsKCWlmICh2YWx1ZSA8PSBwLT5t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