#include <stdio.h>
#include <stdlib.h>
struct list {
int data;
struct list *next;
} List, *PList;
struct list * list_insert (int data, struct list * root)
{
struct list
*p
= (struct list
*) malloc(sizeof (struct list
)); p->data = data;
p->next = NULL;
if (!root)
root = p;
else
{
struct list *iter = root;
while (iter->next)
iter = iter->next;
iter->next = p;
}
return root;
}
void list_print (struct list * root)
{
while (root)
{
root = root->next;
}
}
void list_destroy (struct list * root)
{
if (root != NULL)
{
list_destroy (root->next);
}
}
int main (int argc, char *argv[])
{
struct list *root = NULL;
root = list_insert (1, root);
root = list_insert (2, root);
root = list_insert (3, root);
list_print(root);
list_destroy (root);
list_print(root);
int p;
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnN0cnVjdCBsaXN0IHsKCWludCBkYXRhOwoJc3RydWN0IGxpc3QgKm5leHQ7Cn0gTGlzdCwgKlBMaXN0OwoKc3RydWN0IGxpc3QgKiBsaXN0X2luc2VydCAoaW50IGRhdGEsIHN0cnVjdCBsaXN0ICogcm9vdCkKewoJc3RydWN0IGxpc3QgKnAgPSAoc3RydWN0IGxpc3QgKikgbWFsbG9jKHNpemVvZiAoc3RydWN0IGxpc3QpKTsKCXAtPmRhdGEgPSBkYXRhOwoJcC0+bmV4dCA9IE5VTEw7CglpZiAoIXJvb3QpCgkJcm9vdCA9IHA7CgllbHNlCgl7CgkJc3RydWN0IGxpc3QgKml0ZXIgPSByb290OwoJCXdoaWxlIChpdGVyLT5uZXh0KQoJCQlpdGVyID0gaXRlci0+bmV4dDsKCQlpdGVyLT5uZXh0ID0gcDsKCX0KCXJldHVybiByb290Owp9Cgp2b2lkIGxpc3RfcHJpbnQgKHN0cnVjdCBsaXN0ICogcm9vdCkKewoJd2hpbGUgKHJvb3QpCgl7CgkJcHJpbnRmICgiJWRcbiIsIHJvb3QtPmRhdGEpOwoJCXJvb3QgPSByb290LT5uZXh0OwoJfQp9Cgp2b2lkIGxpc3RfZGVzdHJveSAoc3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