C语言数据结构
用代码块功能插入代码,请勿粘贴截图
typedef char ElemType;
typedef struct
{
ElemType date[MAXSIZE];
int length;
} SeqList;
int InitList_Sq(SeqList *&L){
L=new SeqList;
if(!L)
return ERROR;
L->length=0;
return OK;
}
void DestroyList_Sq(SeqList*&L)
{
delete L;
L=NULL;
}
void ClearList_Sq(SeqList*&L)
{
L->Length;
}
int ListEmpty_Sq(SeqList*L)
{
return (L->length);
}
bool ListEmpty_Sq(SeqList*L)
{
if(L->length==0)
return true ;
else
return false;
}
int GetElem_Sq(SeqList*L,int i,ElemType&e)
{
if(i<1||i>L->length)
return RERRO;
e=L->data[i-1];
return OK;
}
int LocateElem_Sq(SeqList*L,ElemType e)
{
for(int i=1;i<L->length+1;i++)
if (L->data[i-1]==e)
return ERROR;
}
int ListInsert_Sq(SeqList*&L,int,ElemType&e)
{
if(L->length==MAXSIZE)
return ERROR;
if(i<1||i>L->length+1)
return ERROR;
for(int j=L->length-1;j>=i;j--)
L->date[j+1]=L->data[j];
L->date[i-1]=e;
L->length++;
return OK;
}
int ListDelete_Sq(SeqList*&L,int i,ElemType&e)
{
if(ListEmpty_Sq(L))
return ERROR;
if(i<1||i>L->length)
return ERROR;
e=L->dare[i-1];
for(int j=i;j<L->length;j++)
L->dare[j-1]=L->data[j];
L->length--;
return OK;
}
void DispList_Sq(SeqList*L)
{
int i;
printf("顺序表:");
if (ListEmpty_Sq(L)) {
printf("表空!\n");
return;
}
for(i=0;i<L->length;i++)
printf("%c ",L->data[i]);
printf("\n");
}
void showmenu()
{
printf("\n\n\n");
printf(" --线性表顺序存储基本运算演示-- \n");
printf("****************************************");
printf("* 1------顺序表的初始化 *");
printf("* 2------顺序表的初始化 *");
printf("* 3------顺序表的初始化 *");
printf("* 4------顺序表的初始化 *");
printf("* 5------顺序表的初始化 *");
printf("* 6------顺序表的初始化 *");
printf("* 7------顺序表的初始化 *");
printf("* 8------顺序表的初始化 *");
printf("* 9------顺序表的初始化 *");
printf("* *");
printf("* 0------退出 *");
printf("****************************************");
printf("请选择菜单号(0--9):");
}
void List_Sq()
{
char choice='N';
ElemType item;
int position;
SeqList*L;
int fiag=0;
while(choice!=0)
{
shoemenu();
_flushall();
scanf("%c",&choice);
switch(choice)
{
case'1':
printf("初始化顺序表操作\n");
if(InitList_Sq(L))
{
printf("初始化成功!\n");
flag=1;
}
else
printf("初始化失败\n");
break;
case'2':
if(flag)
{
DestroyList_Sq(L);
flag=0;
printf("顺序表删除成功!\n");
}
else
{
printf("顺序表不存在,操作失败!\n");
}
case'3':
if(flag)
{
ClearList_Sq(L);
Printf("顺序表清空成功!\n");
DispList_Sq(L);
}
else
{
printf("顺序表不存在,操作失败!\n");
}
break;
case'4':
if(flag)
{
printf("顺序表元素个数为%d\n",Listlength_Sq(L));
DispList_Sq(L);
}
else{
printf("顺序表不存在,操作失败!\n")
}
case'5':
if(flag)
{
printf("请输入元素的位序号:");
scanf("%d",Position);
if(GetElem_Sq(L,Position,item)==OK)
{
printf("第%d个元素为:%c\n",Position,item);
}
}
else{
printf("顺序表不存在,操作失败!\n")
}
case'6':
if(flag)
{
printf("请输入元素表的位序符号:");
scanf("%d",&Position);
if(GetElem_Sq(L,Position,item)==OK)
{
printf("第%d个元素为:%c\n",Postion,item);
}
else{
printf("输入的位序号错误!\n");
}
DispList_Sq(L);
}
else{
printf("顺序表不存在,操作失败!\n")
}
break;
case'7':
if(flag)
{
printf("请输入元素的值:")
_flushall();
scanf("%c",&item);
Position=LocateElem_Sq(L,item);
if(Position){
printf("该元素找到,位序是%d。\n",Position);
}
else{
printf("该元素没找到!\n");
}
DispList_Sq(L);
}
else{
printf("顺序表不存在,操作失败!\n");
}
case'8':
if(flag)
{
printf("请输入元素的值:")
_flushall();
scanf("%c",&item);
printf("请输入要插入元素的位置序号:");
scanf("%d",&Position);
if(ListInsert_Sq(L,Position,item)==OK)
printf("该元素插入成功!\n");
else
printf("输入的位序号错误!\n");
DispList_Sq(L);
}
else{
printf("顺序表不存在,操作失败!\n")
}
break;
case'9':
if(flag)
{
printf("请输入要删除元素的位置序号:");
scanf("%d",&Position);
if(ListDelete_Sq(L,Position,item)){
printf("删除的元素为%c\n",item);
} else{
printf("输入的位序号错误!\n");
}
DispList_Sq(L);
}
else{
printf("顺序表不存在,操作失败!\n")
}
case'0':
printf("\n\t 程序结束!\n");
DestroyList_Sq(L);
break;
default:
printf("\n\t 选择错误,请重新输入!\n");
break;
}
}
}
int main()
{
List_Sq();
return 0;
}
int InitList_Sq(SeqList *&L)这里为什么会报错,该怎末改,