[c]代码库
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
typedef int ElemType; //假设线性表中的元素均为整型
typedef struct
{
ElemType* elem; //存储空间基地址
int length; //表中元素的个数
int listsize; //表容量大小
} SqList; //顺序表类型定义
int ListCreate_Sq(SqList &L)
{
int n;
scanf("%d",&n);
L.elem=new ElemType[n];
if(!L.elem)
exit(-2);
L.length=0;
L.listsize=n;
for(int i=0; i<n; i++)
{
scanf("%d",&L.elem[i]);
L.length++;
}
return 1;
}
void ListDelete_Sq(SqList &L,ElemType x,ElemType y)
{
int n=L.length;
for(int i=0,j=0; i<n; i++)
{
if(L.elem[i]>=x&&L.elem[i]<=y)
L.length--;
else
L.elem[j++]=L.elem[i];
}
}
int main()
{
SqList L;
ElemType *p;
if(!ListCreate_Sq(L))
{
printf("ListCreate_Sq: 创建失败!!!\n");
return -1;
}
int x,y;
scanf("%d%d",&x,&y);
ListDelete_Sq(L,x,y);
for(p=L.elem; p<L.elem+L.length-1; ++p)
printf("%d ",*p);
printf("%d",*p);
return 0;
}