链表删除指定的值

来源:互联网 发布:我知你好未再百度 编辑:程序博客网 时间:2024/06/05 06:07
#include <iostream>#include<stdio.h>  #include<string.h>  #include<conio.h>  using namespace std;typedef struct list{int data;struct list *next;}node;node *del(node *head,int data){node *p,*q;p=head;q=p;p=p->next;while(p!=NULL){if(p->data==data){q->next=p->next;p=q;}q=p;p=p->next;}return head;}int main(){node *head,*p,*s;head=(node*)malloc(sizeof(node));head->data=0;p=head;for(int i=1;i<10;i++){node *s=(node*)malloc(sizeof(node));s->data=i;p->next=s;p=s;}//head=head->next;p->next=NULL;s=del(head,4);while(s!=NULL){cout<<s->data<<endl;s=s->next;}return 0;}

0 0