#include<stdio.h>#include<stdlib.h>#include"seqlist.h"
seqlist_t *create_seqlist(void){
seqlist_t *L=NULL;
L=(seqlist_t *)malloc(sizeof(seqlist_t));if(L ==NULL){puts("malloc no memory!");returnNULL;}
L->last =-1;return L;}voidclear_seqlist(seqlist_t *L){if(L ==NULL){puts("seqlist_t *L is NULL");return;}free(L);
L =NULL;return;}intis_empty_seqlist(seqlist_t *L){if(L ==NULL){puts("seqlist_t *L is NULL");return-1;}return(L->last ==-1);}intis_full_seqlist(seqlist_t *L){if(L ==NULL){puts("seqlist_t *L is NULL");return-1;}return(L->last == MAXSIZE-1);}voidset_empty_seqlist(seqlist_t *L){if(L ==NULL){puts("seqlist_t *L is NULL");return;}
L->last =-1;return;}intget_length_seqlist(seqlist_t *L){if(L ==NULL){puts("seqlist_t *L is NULL");return-1;}return(L->last+1);}voidshow_seqlist(seqlist_t *L){int i=0;if(L ==NULL){puts("seqlist_t *L is NULL");return;}for(i=0;i<=L->last;i++){printf("L->data[%d] = %d\n",i,L->data[i]);}return;}intinsert_seqlist(seqlist_t *L,data_t x,int pos){int i=0;if(is_full_seqlist(L)|| pos<0|| pos >L->last+1){puts("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++;return0;}intdelete_seqlist(seqlist_t *L,int pos){int i=0;if(pos<0|| pos>L->last){puts("input pos is invalid");return-1;}for(i=pos;i<L->last;i++){
L->data[i]= L->data[i+1];}
L->last--;return0;}intchange_seqlist(seqlist_t *L,data_t x,int pos){if(pos<0|| pos>L->last){puts("input pos is invalid");return-1;}
L->data[pos]= x;return0;}intsearch_seqlist(seqlist_t *L,data_t x){int i=0;if(L ==NULL){puts("seqlist_t *L is NULL");return-1;}for(i=0;i<get_length_seqlist(L);i++){if(L->data[i]== x)return i;}return-1;}
main.c
#include<stdio.h>#include<stdlib.h>#include"seqlist.h"intmain(int argc,constchar*argv[]){int i=0;
seqlist_t *L=NULL;
L=create_seqlist();if(is_empty_seqlist(L))printf("seqlist L is empty\n");printf("last=%d\n",L->last);for(i=0;i<5;i++){insert_seqlist(L,i,i);}printf("last=%d\n",L->last);printf("seqlist L length is %d\n",get_length_seqlist(L));show_seqlist(L);puts("==========yy================================");printf("3 in seqlist L is %d\n",search_seqlist(L,3));delete_seqlist(L,search_seqlist(L,3));printf("seqlist L length is %d\n",get_length_seqlist(L));show_seqlist(L);puts("==========yy================================");change_seqlist(L,8,search_seqlist(L,4));show_seqlist(L);puts("==========yy================================");set_empty_seqlist(L);show_seqlist(L);clear_seqlist(L);return0;}