大概是这样子,没测试过.
void insertnode(node* p,int i)
{
int pos = 0;
node* tmp = head;
node* t = NULL;
while(tmp->next)
{
tmp = tmp->next;
pos++;
if (pos == i)
{
break;
}
}
if (pos < i)
{
return;
}
if (tmp->next == NULL)
{
tmp->next = p;
p->next = NULL;
}
else
{
t = tmp->next;
tmp->next = p;
p->next = t;
}
}
if(head->next!=null)
{
ptr=head-next;
while(ptr->next!=null && i>0)
{
new->next=prt->next;
ptr->next=new;
i--;
}
}
写的有点粗糙