#ifndef __SEQ_LIST_H__
#define __SEQ_LIST_H__
#include<stdio.h>
#include<string.h>
#define N 100
typedef int data_t;
typedef struct {
data_t data[N];
int last;
}seqlist_t;
seqlist_t *create_seqlist(void);
void clear_seqlist(seqlist_t *L);
int insert_seqlist(seqlist_t *L,data_t x,int pos);
int is_full_seqlist(seqlist_t *L);
void show_seqlist(seqlist_t *L);
int is_empty_seqlist(seqlist_t *L);
int set_empty_seqlist(seqlist_t *L);
int get_len_seqlist(seqlist_t *L);
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);
#endif
```c
#include "seq_list.h"
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
seqlist_t *create_seqlist(void)
{
seqlist_t *L = NULL;
L = (seqlist_t *)malloc(sizeof(seqlist_t));
if(L == NULL)
{
printf("内存申请失败\n");
}
L->last = -1;
return L;
}
void clear_seqlist(seqlist_t *L)
{
if(L == NULL)
{
printf("空表\n");
return ;
}
else
{
free(L);
L = NULL;
return ;
}
}
int insert_seqlist(seqlist_t *L,data_t x,int pos)
{
int i = 0;
if(is_full_seqlist(L) || (pos<0) || (pos > L->last+1))
{
puts("insert error");
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 is_full_seqlist(seqlist_t *L)
{
if(L == NULL)
{
printf("空表\n");
}
return (L->last == N - 1);
}
void show_seqlist(seqlist_t *L)
{
if(L == NULL)
{
printf("空表\n");
return ;
}
int i;
for(i = 0;i <= L->last;i++)
{
printf("L->data[%d] = %d\n",i,L->data[i]);
}
}
int is_empty_seqlist(seqlist_t *L)
{
if(L == NULL)
{
printf("seqlist is NULL \n");
return -1;
}
return (L->last == -1);
}
int set_empty_seqlist(seqlist_t *L)
{
if(L == NULL)
{
printf("seqlist is NULL \n");
return 0;
}
else
{
L->last = -1;
}
return 1;
}
int get_len_seqlist(seqlist_t *L)
{
int len;
if(L == NULL)
{
printf("seqlist is NULL \n");
return 0;
}
len = L->last+1;
return len ;
}
int delete_seqlist(seqlist_t *L,int pos)
{
int i;
if((pos < 0) || (pos > L->last))
{
printf("pos is invaild\n");
return 0;
}
for(i = pos;i <= L->last;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))
{
printf("pos is invaild\n");
return 0;
}
L->data[pos] = x;
return 0;
}
int search_seqlist(seqlist_t *L,data_t x)
{
int i = 0;
for(i = 0;i<=L->last;i++)
{
if(L->data[i] == x)
return i;
}
printf("no find \n");
return -1;
}