node *delete_one_node(node *head,int num) {
node *p1,*p2; if(head==NULL) {
cout<<\链表为空,无结点可删!\\n\ return(NULL); }
if(head->data==num) {
p1=head; head=head->next; delete p1;
cout<<\删除了一个结点!\\n\ } else {
p2=p1=head;
while(p2->data!=num&&p2->next!=NULL) { p1=p2; p2=p2->next;
}
if(p2->data==num) {
p1->next=p2->next; delete p2;
cout<<\删除了一个结点!\\n\ } else
cout< return(head); } //释放链表的结点空间 node * deletechain(node *h) { node *p1; while(h) { p1=h; h=h->next; delete p1; } cout<<\已释放链表的结点空间!\\n\ return (h); } 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<<\链表为空,无结点可删!\\n\ return(NULL); } p=head; if(k==1) { p=head; head=head->next; delete p; cout<<\删除了第一个结点!\\n\ } else{ p=find(head,k-1);//查找第K-1个结点,并由P指向该结点 if(p->next !=NULL){ p1=p->next; p->next=p1->next; delete p1; cout<<\删除了第\个结点!\\n\ } return(head); } void main(void) { node *head; int num; int k; head=create_sort(); print(head); cout<<\结点数:\ cout<<\输入要删除结点上的序号!\\n\ cin>>k; head=delete_k_node(head,k); print(head); cout<<\输入要删除结点上的整数!\\n\ cin>>num; head=delete_one_node(head,num); print(head); deletechain(head); cout<<\输入要插入的整数!\\n\ cin>>num; head=insert(head,num); print(head);