编写一个删除顺序表中为指定值的元素
测试输入:
3
1 2 3
3
预期输出:
del "3" 1 times
1 2
#include <stdio.h>
#include <iostream>
#include "seqList.h"
using namespace std;
int main()
{
seqList L;
ElemType e[10];
int n;
scanf("%d",&n);
for (int i = 0; i < n; i++)
{
scanf("%d",&e[i]);
}
seqListInitFromArray(L,e,n);
//测试删除
int x;
scanf("%d",&x);
int c = seqListDelEle(L,x);
printf("del \"%d\" %d times\n", x,c);
seqListPrint(L);
return 0;
}
typedef struct
{
ElemType *elem;
int length; //当前数据的实际长度(有多少数据)
} seqList;
Status seqListInit(seqList &L);
Status seqListInitFromArray(seqList &L , ElemType a[], int n);
Status seqListInsert(seqList &L, int i, ElemType e);
Status seqListDel(seqList &L, int i, ElemType& e);
//删除线性表中的值为e的元素, 返回成功删除的个数
int seqListDelEle(seqList &L, ElemType e);
//查找e,返回位置;如果不存在,返回ERROR
Status Find( seqList &L, ElemType e );
void seqListPrint(seqList &L);