#define MAXSIZE 100
#define ok 1
#define error 0
#include"malloc.h"
#include<conio.h>
#include<iostream.h>
typedef int status;
#include "stdlib.h"
#define LIST_INIT_SIZE 100
//#define LISTINCREMENT 10
typedef struct sqlist
{
int *elem;
int length;
int listsize;
//int elem[100];
}sqlist;
status initlist_sq(sqlist &L)
{
L.elem =(int*)malloc(MAXSIZE*sizeof(int));
if (!L.elem ) exit(error);
L.length =0;
L.listsize =LIST_INIT_SIZE;
return ok;
}
void creatlist(sqlist &L)
{int temp;
L.length=0;
cin>>temp;
while(temp>0)
{L.elem[L.length]=temp;
L.length++;
cin>>temp;}
}
void delete_data(sqlist &L,int e)
{
int j,i;
if ((i<0) || (i>L.length-1))
{cout<<"Not exist"<<endl;}
else
{
for (j=i+1;j<=L.length-1;j++)
{L.elem[j-1]=L.elem[j];
L.length--;
}
}
void insert_data(sqlist &L,int i, int e)?
{
int j;?
if ((i<0)||(L>L.length))
cout<<"Error!"<<endl;
else
{
for (j=L.length-1;j>=i;j--)
L.elem[j+1]=L.elem[j];
L.elem[i]=e;?
L.length++;?
}?
}
void show(&L)
{
int j;
for(j=1;j<=L.length;j++)
cout<<L.elem[j]<<" ";
cout<<endl;
}
void main()
{ sqlist L;
int e;
int n;
initlist_sq(L)
creatlist(L)
show(L);
cout<<endl;
cout<<"输入要插入元素及位置:";
cin>>e>>j;
insert_data(&L,e,j);
show(L);
cout<<endl;
cout<<:"请输入要删除的元素位置:"
cin>>j;
delete_data(&L,j);
show(L);
}