#include <stdlib.h>
#include <stdio.h>
typedef int data_type ;
struct node_type
{
struct node_type* next ;
data_type data ;
};
typedef struct list_type
{
struct node_type* head ;
} List ;
List List_Create()
{
List list = { NULL } ;
return list ;
}
int List_AddItem(List* list, data_type item)
{
struct node_type
* newNode
= malloc(sizeof(struct node_type
)) ;
if ( newNode )
{
newNode->data = item ;
newNode->next = list->head ;
list->head = newNode ;
return 1 ;
}
return 0 ;
}
void List_Destroy(List* list)
{
struct node_type* curNode = list->head ;
while ( curNode )
{
list->head = curNode->next ;
curNode = list->head ;
}
}
void List_Print(const List* list)
{
const struct node_type* curNode = list->head ;
while ( curNode )
{
printf( "%d\n", curNode
->data
) ; curNode = curNode->next ;
}
}
int main()
{
List list = List_Create() ;
for ( int i=0; i<10; ++i )
List_AddItem(&list, i);
List_Print(&list) ;
List_Destroy(&list) ;
}
I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RkaW8uaD4KCnR5cGVkZWYgaW50IGRhdGFfdHlwZSA7CgpzdHJ1Y3Qgbm9kZV90eXBlCnsKICAgIHN0cnVjdCBub2RlX3R5cGUqIG5leHQgOwogICAgZGF0YV90eXBlIGRhdGEgOwp9OwoKdHlwZWRlZiBzdHJ1Y3QgbGlzdF90eXBlCnsKICAgIHN0cnVjdCBub2RlX3R5cGUqIGhlYWQgOwp9IExpc3QgOwoKTGlzdCBMaXN0X0NyZWF0ZSgpCnsKICAgIExpc3QgbGlzdCA9IHsgTlVMTCB9IDsKICAgIHJldHVybiBsaXN0IDsKfQoKaW50IExpc3RfQWRkSXRlbShMaXN0KiBsaXN0LCBkYXRhX3R5cGUgaXRlbSkKewogICAgc3RydWN0IG5vZGVfdHlwZSogbmV3Tm9kZSA9IG1hbGxvYyhzaXplb2Yoc3RydWN0IG5vZGVfdHlwZSkpIDsKCiAgICBpZiAoIG5ld05vZGUgKQogICAgewogICAgICAgIG5ld05vZGUtPmRhdGEgPSBpdGVtIDsKICAgICAgICBuZXdOb2RlLT5u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