插入节点:
if(list == NULL)
{
return ;
}
if(data == NULL)
{
return ;
}
if(pos<0 || pos >list->size)
{
pos=list->size;
}
//创建新的结点
LinkNode *newnode=(LinkNode *)malloc(sizeof(LinkNode));
newnode->data=data;
newnode->next=NULL;
//找结点
//辅助指针变量
LinkNode *pcurrent=list->head;
int i;
for(i=0;i<pos;i++)
{
pcurrent=pcurrent->next;
}
//新结点插入链表
newnode->next=pcurrent->next;
pcurrent->next=newnode;
list->size++;
删除节点:
if(list == NULL)
{
return ;
}
if(pos<0 || pos >list->size)
{
return ;
}
//找结点
//辅助指针变量
LinkNode *pcurrent=list->head;
int i;
for(i=0;i<pos;i++)
{
pcurrent=pcurrent->next;
}
//删除结点
LinkNode *delnode=pcurrent->next;
pcurrent->next=delnode->next;
free(delnode);
list->size--;