从顺序表L中删除所有值为x的元素

#include 
#define MAXSIZE 100
typedef struct
{
int elem[MAXSIZE];
int last;
}SeqList;
int creat(SeqList &L)
{
int a;
printf("请输入要创建的元素的个数:\n");
scanf("%d", &a);
L.last=0;
for (int i = 0;ilast)
{  
if (L->elem[i] != x)
{
L->elem[j] = L->elem[i];
i++;
j++;
}
else i++;
}
L->last = j - 1;
printf("creat last=%d\n", L->last);


}


void main()
{
SeqList L;
int a,i,length;
L.last=creat(L);
show(L);
printf("请输入删除的数值:\n");
scanf("%d", &a);
delx(&L, a);
printf("删除后的线性表为:\n");
for (i = 0;i < L.last;i++)
printf("%d\n", L.elem[i]);
}

你可能感兴趣的:(数据结构)