#include<iostream>
#include<stdlib.h>
using namespace std;
#define error -1
#define ok 1
typedef int Status;
typedef int ElemType;
typedef struct LNode
{
ElemType data;
LNode *next;
}LNode,*LinkList;
Status CreateList (LinkList &L,int n);
Status PrintList(LinkList L);
void DeleList(LinkList &L,ElemType e);
int main()
{
LinkList L;
ElemType e;
int n;
cout<<"请输入数据个数:";
cin>>n;
CreateList(L,n);
cout<<"请输入要删除的元素";
cin>>e;
DeleList(L,e);
}
Status CreateList(LinkList &L,int n)
{
L=new LNode;
L->next=NULL;
LNode *p;
LNode *r=L;
for(int i=0;i<n;++i)
{
p=new LNode;
cin>>p->data;
p->next=NULL;
r->next=p;
r=p;
}
}
void DeleList(LinkList &L,ElemType e)
{
LNode *q;
LNode *p;
p=L;int j=0;
while(p->next!=NULL)
{
if(p->next->data==e)
{
q=p->next;
p->next=q->next;
delete q;
}
else p=p->next;
}
PrintList(L);//输出结果
}
Status PrintList(LinkList L)
{
LNode* p = L->next;
while (p != NULL)
{
cout << p->data <<" ";
p=p->next;
}
cout << endl;
return ok;
}
标签:Status,单链,LNode,删除,int,ElemType,元素,next,LinkList
From: https://blog.csdn.net/2302_80440382/article/details/136935909