#include<stdio.h>#include<stdlib.h>#include"seqlist.h"#include<stdbool.h>/* run this program using the console pauser or add your own getch, system("pause") or input loop */voidshowmenu(void){printf("1.插入元素\n");printf("2.删除元素\n");printf("3.获取元素\n");printf("4.元素个数\n");printf("5.遍历\n");printf("0.销毁\n");}voidprint(int num){printf("%d",num);}voidtest(void){size_t cap =0;
seqlist seq;printf("请输入容量\n");scanf("%u",&cap);int ret =seq_list_init(&seq,cap);if(ret ==0){printf("成功\n");}else{printf("失败\n");return;}// return;size_t pos =0;int element =0;while(true){showmenu();int opt =0;scanf("%d",&opt);switch(opt){case0:seq_list_destroy(&seq);printf("over\n");return;case1:printf("插入的位置\n");scanf("%d",&pos);printf("插入的元素\n");scanf("%d",&element);
ret =seq_list_insert(&seq,pos,element);if(ret ==0){printf("插入成功\n");}else{printf("插入失败\n");}break;case2:printf("删除\n");scanf("%u",&pos);
ret =seq_list_delete(&seq,pos,&element);break;case3:printf("位置\n");scanf("%d",&pos);
ret =seq_list_get(&seq,pos,&element);printf("成功\n");printf("%d\n",element);break;case4:printf("顺序表中的元素个数为:%u\n",seq_list_size(&seq));break;case5://printf("-------");seq_list_travel(&seq,print);printf("\n");break;}}}intmain(int argc,char*argv[]){test();return0;}
顺序表main函数,测试代码#include <stdio.h>#include <stdlib.h>#include "seqlist.h"#include <stdbool.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ void showmenu(void){ printf("1.插入元