项目场景:
本题要求实现一个函数,可删除顺序表中的偶数元素。
函数接口定义:
void Del_even(SqList *L);
其中 L是待删除元素的顺序表,也是删除后返回的顺序表。
裁判测试程序样例:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
typedef int DataType;
#define LISTSIZE 100
typedef struct
{
DataType items[LISTSIZE]; /* 存放顺序表元素的数组 /
int length; / 表示线性表的当前表长 */
}SqList;
int InitSqList(SqList L)
{ / L为指向顺序表的指针 /
L->length = 0;
return 1;
}
int SqListEmpty( SqList L )
{/ L为顺序表 */
if( L.length <= 0 )
return 1;
else
return 0;
}
int SqListInsert( SqList *L, int pos, DataType item )
{
int j;
if ( L->length == LISTSIZE ) // "溢出”处理
{
printf(“overflow!\n”);
return 0;
}
if ( (pos<=0) || (pos > L->length+1) ) // pos值"超出”处理
{
printf(“position is error!/n”);
return 0;
}
for (j = L->length -1; j >=pos-1; j–)
L-> items[j+1] = L-> items[j]; //后移一个位置
L-> items[pos-1] = item; //新的数据元素写入
L->length++; //线性表的长度增加1
return 1;
}
int SqListDelete ( SqList *L, int pos, DataType item )
{/ L为指向顺序表的指针,pos为删除位置,用于item返回被删元素 */
int i;
if( SqList