该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
{
p1=p2;
p2=p2->next;
}
if (p2->data==num)
{
p1->next=p2->next;
delete p2;
cout<
}
else cout<
}
return(head);
}
//释放链表的结点空间
void deletechain(node *h)
{
node *p1;
while(h)
{
p1=h;
h=h->next;
delete p1;
}
cout<
}
int count(node *head)//求链表的结点数
{
int n;
node *p;
p=head;
n=0;
while(p!=NULL)
{
n=n+1;
p=p->next;
} return(n);
}
//删除链表上第k 个结点
node *delete_k_node(node *head,int k)
{
int j=1;
node *p,*p1;
if(head==NULL)
{
cout<
return(NULL);
}
p=head;
if (k==1)
{
p=head;
head=head->next;
delete p;
cout<
}
else
{
p=find(head,k-1); //查找第k-1 个结点,并由p 指向该结点
if (p->next!=NULL)
{
p1=p->next;
p->next=p1->next;
delete p1;
cout<
}
return(head);
}
}
void main(void)
{
node *head;
int num;
int k;
head=create_sort();
print(head);
cout<
cout<
cin>>num;
head=delete_k_node(head,k);
print(head);
cout<
cin>>num;
head=delete_one_node(head,num);
print(head);
deletechain(head);
cout<
cin>>num;
head=insert(head,num);
print(head);
}