链表结点的删除

来源:互联网 发布:淘宝店铺转让价格 编辑:程序博客网 时间:2024/06/06 07:37
#include <iostream>#include <stdio.h>using namespace std;//typedef char DataType;struct Node{    char data;    int jishu;    Node *next;    };//typedef Node *LinkList;int main(){    Node *head=NULL;    head=new(Node);    char c;    cin>>c;    head->data=c;    Node *p=head;    int i=2;    while(c=getchar(),c!='\n'){        p->next=new(Node);        p=p->next;        p->data=c;        p->jishu=i;        p->next=NULL;        i++;    }    Node *q=head;    Node *m=NULL;    while(q!=NULL){        if(q->next->data=='w'){          m=q->next;//这里一定要想清楚,容易出错的地方<q->next=m->next;//这里一定要想清楚,容易出错的地方            break;        }        else{            q=q->next;        }    }    Node *n=head;    while(n!=NULL){    cout<<n->data;    n=n->next;    }    cout<<endl;    return 0;}

0 0
原创粉丝点击