/*********建立从头插入,不带表头的链表********/
//参数为头结构指针和要插入的数据
linck *InitList(linck *root, int data)
{
linck *newlinck; // 新的结点
static linck *prelinck;
newlinck = (linck*)malloc(sizeof(linck));
if(!newlinck)
{
printf("内存分配失败!!!/n");
exit(1);
}
newlinck->next = NULL;
newlinck->x = data;
if(NULL== root)
{
root = newlinck;
prelinck = root;
}
else
{
prelinck->next = newlinck;
prelinck = newlinck;
}
return root; //返回头结点
}
/*********销毁链表***********/
void DestroyList(linck* root)
{
linck *ptr;
ptr = root;
while(root != NULL)
{
ptr = ptr->next;
free(root);
root = ptr;
}
}