#include<iostream>
using namespace std;
typedef struct
{
int *elem;
int length;
}SqList;
void CreateList(SqList &L,int n)
{
for(int i=0;i<n;i++)
{
cin>>L.elem[i];
}
L.length=n;
}
void Delete_e(SqList &L,int e)
{
int i=0,j=0;
while(i<L.length)
{
if(L.elem[i]!=e)
{
L.elem[j]=L.elem[i];
i++;
j++;
}else
{
i++;
}
}
L.length=j;
}
void display(SqList &L)
{
for(int i=0; i<L.length; i++)
{
cout<<L.elem[i]<<" ";
}
}
int main()
{
SqList L;
int n;
cout<<"请输入线性表长度:";
cin>>n;
cout<<"请输入线性表元素的值:";
CreateList(L,n);
int e;
cout<<"请输入你想删除的元素:";
cin>>e;
Delete_e(L,e);
cout<<"当前线性表为:";
display(L);
return 0;
}
版权声明:本文为weixin_46803686原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。