1197: 线性表删除元素
时间限制: 1 Sec 内存限制: 128 MB
提交: 14 解决: 13
[提交][状态][讨论版][命题人:uzzoj]
题目描述
利用线性表顺序存储的动态存储,实现创建线性表,以及删除线性表中的某个元素
输入
输入包括:输入元素个数,以及相应的线性表元素,以及要删除的位置
输出
输出删除后的线性表
样例输入
5 1 2 3 4 5 3
样例输出
1 2 4 5
#include <stdio.h>
#include <stdlib.h>
#define ERROR 0
#define OK 1
typedef struct
{
int *elem;
int length;
int Listsize;
} Sqlist;
int initList_Sq(Sqlist *LA,int len)
{
LA->elem=(int *)malloc(sizeof(int)* len);
if(!LA->elem)return ERROR;
LA->length=0;
LA->Listsize=len;
return OK;
}
int delList_Sq(Sqlist *LA,int location)
{
int j;
if(location<1&&location>LA->length+1) return ERROR;
for(j=location; j<LA->length; j++)
{
LA->elem[j-1]=LA->elem[j];
}
LA->length--;
return OK;
}
int main()
{
Sqlist *LA;
int a_len,i;
scanf("%d",&a_len);
LA=(Sqlist *)malloc(sizeof(Sqlist));
initList_Sq(LA ,a_len);
for(i=0; i<a_len; i++)
{
scanf("%d",&LA->elem[i]);
LA->length++;
}
int location;
scanf("%d",&location);
delList_Sq(LA,location);
for(i=0; i<LA->length; i++)
{
printf("%d ",LA->elem[i]);
}
}