资源描述:
《数据结构,顺序表初始化,求顺序表长度,插入删除,取数据元素,查找,遍历》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、数据结构,顺序表的初始化,求顺序表的长度,插入删除,取数据元素,查找,遍历#include#include#defineNULL0#defineMAXSIZE1024/*顺序表可能的最大长度,假设为1024*/typedefintelemtype;/*elemtype可为任意类型,假设为int型*/typedefstructsequlist{elemtypedata[MAXSIZE];/*定义顺序表为一维数组*/intlast;/*last为表中最后一个数据元素的下标位
2、置*/}SequenList;/*顺序表的结构类型为SequenList*//*函数声明*/SequenList*Init_SequenList();intSequenList_Length(SequenList*L);intInsert_SequenList(SequenList*L,elemtypex,inti);voidmenu();intDelete_SequenList(SequenList*L,inti);elemtypeGetData_SequenList(SequenList*L,inti)
3、;intSearch_SequenList(SequenList*L,elemtypekey);voidPrint_SequenList(SequenList*L);voidSequenList_Iuput(SequenList*L);/*主函数*/voidmain(){charcmd;inti,Length,isdo;elemtypex,data,key;SequenList*L=NULL;system("cls");menu();while((cmd=getchar())!='#'){switch(cm
4、d){case'1':L=Init_SequenList();printf("Creatingthelist!");printf("ttt");break;case'2':L=SequenList_Iuput(L);printf("Inputingdata....");printf("ttt");break;case'3':Length=SequenList_Length(L);printf("TheLengthofthelistis%d",Len
5、gth);printf("ttt");break;case'4':printf("input....",i,x);scanf("%d%d",&i,&x);x=Insert_SequenList(L,x,i);printf("Insertingthedataintothelist!");printf("ttt");break;case'5':isdo=Delete_SequenList(L,i);printf("Deletingthedatainthelist.
6、.....");printf("ttt");break;case'6':printf("%d",i);scanf("%d",&i);x=GetData_SequenList(L,i);if(x!=0)printf("%d%d",i,x);printf("Getingthedataoftheposition...");printf("ttt");break;case'7':data=Search_SequenList(L,key);printf("Searc
7、hingthedata...");printf("ttt");break;case'8':printf("Displayingthealldataofthelist!...");printf("ttt");break;}fflush(stdin);system("pause");menu();}}voidmenu(){system("cls");printf("tt1-initiallist");printf("tt2-inputdata");pr
8、intf("tt3-getlength");printf("tt4-insertavalue");printf("tt5-delete");printf("tt6-getthedataoftheiposition");printf("tt7-searchadata");printf("tt8-display");printf("tt#-quit");prin