#include<stdio.h>#include<stdlib.h>#include<windows.h>//宏定义 #defineMAXSIZE20#defineXS35#defineYH12#defineWIDTH20#defineHEIGHT20//定义顺序表的结构体类型 typedefstructNode{int*elem;int length;}SqList;//函数的声明voidgotoxy(int x,int y);//坐标移动函数 voidCreatList(SqList &L);//顺序表的创建函数voidwindow();//窗口 voidmenu(SqList &L);//菜单 voidinsert(SqList &L);//插入 voidTraveList(SqList &L);//遍历打印 voiddeletList(SqList &L);//顺序表的删除操作//坐标移动函数 voidgotoxy(int x,int y){
COORD pos;
pos.X = x -1;
pos.Y = y -1;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}//顺序表的创建函数voidCreatList(SqList &L){window();gotoxy(XS, YH -9);
L.elem =(int*)malloc(sizeof(int)* MAXSIZE);if(!L.elem){printf("ERROR\n");exit(0);}printf("please input you want length:\t");scanf("%d",&L.length);gotoxy(XS, YH -8);printf("please input %d number\n", L.length);gotoxy(XS, YH -7);for(int i =0; i < L.length ; i ++){scanf("%d",&L.elem[i]);}gotoxy(XS, YH -6);printf("顺序表创建成功\n");TraveList(L);gotoxy(XS -7, YH);int flag;printf("input 1 back to menu or input 0 output menu\n");gotoxy(XS -4, YH +1);scanf("%d",&flag);if(flag ==0){system("cls");printf("GOODBYE");exit(0);}else{system("cls");menu(L);}}//顺序表的插入voidinsert(SqList &L){if(!L.elem){menu(L);}window();int flag;gotoxy(XS, YH -9);int p, num;printf("please input insert position:\t");scanf("%d",&p);if(p > L.length +1|| p <1){printf("ERROR");system("cls");menu(L);}else{gotoxy(XS, YH -7);printf("please input insert Data:\t");scanf("%d",&num);}for(int i = L.length -1; i >= p -1; i --){
L.elem[i +1]= L.elem[i];}
L.elem[p -1]= num;
L.length ++;TraveList(L);gotoxy(XS -4, YH +1);printf("input 1 back to menu or input 0 output menu\n");scanf("%d",&flag);if(flag ==0){system("cls");printf("GOODBYE");exit(0);}else{system("cls");menu(L);}}//顺序表的删除操作voiddeletList(SqList &L){if(!L.elem){menu(L);}window();gotoxy(XS, YH -9);int p;printf("please input delet position:\t");scanf("%d",&p);if(p > L.length || p <1){printf("ERROR");system("cls");menu(L);}for(int i = p -1; i < L.length ; i ++){
L.elem[i]= L.elem[i +1];}
L.length --;TraveList(L);int flag;gotoxy(XS -4, YH +1);printf("input 1 back to menu or input 0 output menu\n");scanf("%d",&flag);if(flag ==0){system("cls");printf("GOODBYE");exit(0);}else{system("cls");menu(L);}}//菜单 voidmenu(SqList &L){window();int n =10;gotoxy(XS + n, YH -8);printf("1.创建顺序表");gotoxy(XS + n, YH -6);printf("2.插入数据");gotoxy(XS + n, YH -4);printf("3.删除数据");gotoxy(XS + n, YH -2);printf("0.退出");gotoxy(XS , YH +6);printf("please input \t");int p;scanf("%d",&p);switch(p){case1:system("cls");CreatList(L);break;case2:system("cls");insert(L);break;case3:system("cls");deletList(L);break;case0:system("cls");printf("GOODBYE");exit(0);}}//遍历打印 voidTraveList(SqList &L){gotoxy(XS +40, YH -10);for(int i =0; i < L.length ; i ++){gotoxy(XS +40, YH -7+ i);printf("%d", L.elem[i]);}}//框框voidwindow(){system("color 4");int n =10, m =10;gotoxy(XS - n, YH - m);printf("★★★★★★★★★★★★★★★★★★★★★★★★★★★★★");for(int i =0; i < HEIGHT ; i ++){gotoxy(XS - n, YH - m +1);printf("★");
m --;}printf("★★★★★★★★★★★★★★★★★★★★★★★★★★★★");
m ++;for(int i =0; i < HEIGHT ; i ++){gotoxy(XS + n *4-2, YH - m +1);printf("★");
m ++;}for(int i =0; i < HEIGHT ; i ++){gotoxy(XS + n *4+7, YH - m +1);printf("★");
m --;}}//主函数 intmain(){
SqList L;menu(L);}