#define MAXSIZE 100
typedef int data_t;
typedef struct{
data_t data[MAXSIZE];
int last;
}seqlist_t;
seqlist_t *create_seqlist(void);
void release_seqlist(seqlist_t *L);
int is_empty_seqlist(seqlist_t *L);
int is_full_seqlist(seqlist_t *L);
void set_seqlist(seqlist_t *L);
int get_lenth_seqlist(seqlist_t *L);
void show_seqlist(seqlist_t *L);
int insert_seqlist(seqlist_t *L,data_t x,int pos);
int delete_seqlist(seqlist_t *L,int pos);
int change_seqlist(seqlist_t *L,data_t x,int pos );
int search_seqlist(seqlist_t *L,data_t x);
seqlist_t *create_seqlist(void)
{
seqlist_t *L = NULL;
L = (seqlist_t *)malloc(sizeof(seqlist_t));
if(L == NULL) {
put("no memory");
return NULL;
}
L->last = -1;
return L;
}
void release_seqlist(data_t *L)
{
if(L == NULL) {
put("seqlist_t *L is NULL");
return ;
}
free(L);
return ;
}
int is_empty_seqlist(seqlist_t *L)
{
if(L == NULL) {
put("seqlist_t *L is NULL");
return -1;
}
return (L->last == -1);
}
int is_full_seqlist(seqlist_t *L)
{
if(L == NULL) {
put("seqlist_t *L is NULL");
return -1;
}
return (L->last == MAXSIZE-1);
}
void set_seqlist(seqlist_t *L)
{
if(L == NULL) {
put("seqlist_t *L is NULL");
return ;
}
L->last = -1;
return ;
}
int get_lenth_seqlist(seqlist_t *L)
{
if(L == NULL) {
put("seqlist_t *L is NULL");
return -1;
}
return (L->last + 1);
}
void show_seqlist(seqlist_t *L)
{
int i = 0;
if(L == NULL) {
put("seqlist_t *L is NULL");
return ;
}
for(i = 0 ;i <= L-last;i++)
printf("L->data[%d] = %d\n",i,L->data[i]);
return ;
}
int insert_seqlist(seqlist_t *L,data_t x,int pos)
{
int i = 0;
if(is_full_seqlist(L) || (pos < 0) || (pos > L->lsat + 1) ) {
put("input argv is invalid");
return -1;
}
for(i = L->last;i >= pos;i++)
L->data[i + 1] = L->data[i];
L->data[pos] = x;
L->last++;
return 0;
}
int delete_seqlist(seqlist_t *L,int pos)
{
i = 0;
if((pos < 0) || (pos > L->last)) {
put("input pos is invalid");
return -1;
}
for(i = pos;i < get_lenth_seqlist(L);i++)
L->data[i] = L->data[i + 1];
L->last--;
return 0;
}
int change_seqlist(seqlist_t *L,data_t x,int pos )
{
if((pos < 0) || (pos > L->last)) {
put("input pos is invalid");
return -1;
}
L->data[pos] = x;
return 0;
}
int search_seqlist(seqlist_t *L,data_t x)
{
int i;
for(i = 0;i <= L->last;i++) {
if(L->data[i] == x)
return i;
return -1;
}
}