永发信息网

c 代码 线性表的实现

答案:3  悬赏:80  手机版
解决时间 2021-05-11 19:35

#include "stdio.h"
#define list_init_size 100
#define listincreament 10
#define ElemType char
enum status{ok,fail};
typedef struct{
ElemType *elem;
int length;
int listsize;
}sqlist;

enum status initlist_sq(sqlist *L)
{
L->elem=(ElemType*)malloc(list_init_size*sizeof(ElemType));
if(L->elem)
{
L->length=0;
L->listsize=list_init_size;
return(ok);
}
else return (fail);
}

enum status listinsert_sq(sqlist *L,int i,ElemType e)
{
char *newbase;
char *p,*q;
if(i<1||i>L->length+1) return fail;
else
{
if(L->length>=L->listsize)
{
newbase=(ElemType*)realloc(L->elem,(L->listsize+listincreament)*sizeof(ElemType));
if(!newbase) {return fail;goto loop0;}

L->elem=newbase;
L->listsize+=listincreament;
}
q=&L->elem[i-1];
for(p=&L->elem[L->length-1];p>=q;--p)
*(p+1)=*p;
*q=e;
++L->length;
return (ok);
}
loop0:printf("not successfull\n");
}

enum status listdelete_sq(sqlist *L,int i,ElemType *e)
{
char *p,*q;
if(i<1||i>(*L).length) return fail;
else
{
p=&L->elem[i-1];
q=&L->elem[L->length-1];
e=p;
for(++p;p<=q;++p) *(p-1)=*p;
--L->length;
return ok;
}
}

void main()
{
sqlist *L;char e,k;int i;
enum status m;
m=initlist_sq(L);
if(m!="ok")
{
printf("not successfull\n");
exit();

}
printf("please input the dataes:\n");
i=1;
while(1)
{
scanf("%s",&e);
getchar();
m=listinsert_sq(L,i,e);
i++;
if(m==fail){printf("not successfull\n");break;}
printf("please input stop or continue\n");

scanf("%s",&k);

if(k=="stop") break;

}
printf("you want insert the data y or n ?\n");
scanf("%c",&k);
if(k=='y')
while(1)
{
printf("data:e=");
scanf("%s",&e);
printf("\n");
printf("location:i=");
scanf("%d",&i);
printf("\n");
m=listinsert_sq(L,i,e);
if(m!=ok){printf("not successful\n");goto loop1;}
printf(" is successfull\n");
printf("you want to continue insert other data y or n?\n");
scanf("%c",&k);
if(k!='y') break;
}
loop1:printf(" you want to delete the data y or n?\n");
scanf("%c",&k);
if(k=='y')
loop2:
while(1)
{
printf("i=");
scanf("%d",&i);
m=listdelete_sq(L,i,&e);
if(m!='ok'){printf("not successful\n");goto loop2;}
printf("%s",e);
printf("is deleted\n");
printf("you want to continue todelete other data y or n?\n");
scanf("%c",&k);
if(k!='y') break;
}
printf("you want to display the data y or n\n");
scanf("%c",&k);
if(k=='y')
while(i<=L->length)
{
printf("%s",L->elem[i]);
}
else
printf("don't display\n");
}

不知为什么 不能运行 又没错 误了

最佳答案

头文件呢~?

全部回答

错误不少啊,先帮你改了编译错误,你自已试着动行看看,还有什么问题

#include "stdafx.h" #include "stdio.h" #define list_init_size 100 #define listincreament 10 #define ElemType char enum status{ok,fail}; typedef struct{ ElemType *elem; int length; int listsize; }sqlist; enum status initlist_sq(sqlist *L) { L->elem=(ElemType*)malloc(list_init_size*sizeof(ElemType)); if(L->elem) { L->length=0; L->listsize=list_init_size; return(ok); } else return (fail); } enum status listinsert_sq(sqlist *L,int i,ElemType e) { char *newbase; char *p,*q; if(i<1||i>L->length+1) return fail; else { if(L->length>=L->listsize) { newbase=(ElemType*)realloc(L->elem,(L->listsize+listincreament)*sizeof(ElemType)); if(!newbase) {return fail;goto loop0;}

L->elem=newbase; L->listsize+=listincreament; } q=&L->elem[i-1]; for(p=&L->elem[L->length-1];p>=q;--p) *(p+1)=*p; *q=e; ++L->length; return (ok); } loop0:printf("not successfull\n"); } enum status listdelete_sq(sqlist *L,int i,ElemType *e) { char *p,*q; if(i<1||i>(*L).length) return fail; else { p=&L->elem[i-1]; q=&L->elem[L->length-1]; e=p; for(++p;p<=q;++p) *(p-1)=*p; --L->length; return ok; } }

void main() { sqlist *L = (sqlist*)malloc(sizeof(sqlist)); char e,k; int i; enum status m;

m=initlist_sq(L); if(m!=ok) { printf("not successfull\n"); free(L); L=NULL; exit(0);

} printf("please input the dataes:\n"); i=1; while(1) { scanf("%s",&e); getchar(); m=listinsert_sq(L,i,e); i++; if(m==fail){printf("not successfull\n");break;} printf("please input Stop or Continue\n");

char temp[10]; scanf("%s",&temp);

if(temp=="stop") break;

} printf("you want insert the data y or n ?\n"); scanf("%c",&k); if(k=='y') while(1) { printf("data:e="); scanf("%s",&e); printf("\n"); printf("location:i="); scanf("%d",&i); printf("\n"); m=listinsert_sq(L,i,e); if(m!=ok){printf("not successful\n");goto loop1;} printf(" is successfull\n"); printf("you want to continue insert other data y or n?\n"); scanf("%c",&k); if(k!='y') break; } free(L); loop1:printf(" you want to delete the data y or n?\n"); scanf("%c",&k); if(k=='y') loop2: while(1) { printf("i="); scanf("%d",&i); m=listdelete_sq(L,i,&e); if(m!='ok'){printf("not successful\n");goto loop2;} printf("%s",e); printf("is deleted\n"); printf("you want to continue todelete other data y or n?\n"); scanf("%c",&k); if(k!='y') break; } printf("you want to display the data y or n\n"); scanf("%c",&k); if(k=='y') while(i<=L->length) { printf("%s",L->elem[i]); } else printf("don't display\n"); }

不是没错误了...首先你就少了头文件 #include <stdlib.h>

先加上这个头文件你再看看...好象还有些错误...好象是关于你的那个枚举的哇.....

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
周杰伦今年新专辑撒时出
开一间衣时尚的店成本大吗?
怎么说为卫生语句,描写厂区环境卫生的语句
在南通那里有夜晶电视买
花木兰姓什么?
铃兰哪里有卖啊
表现人悲伤的诗词,形容人悲伤的句子
SJ-M和飞轮海比哪个较受欢迎?
求助: B、C类研究生考生分数线如何划定?
什么手机网下载游戏免费?
软中华烟一箱多少条,软中华香烟一箱有多少条
从东环书市可以坐几路车到柳州市新人民医院
佛山什么时候才有地铁?
WOW SS有必要开双天幅吗?
要一个 “葵”字
推荐资讯
教师送给学生生日祝福,老师如何送给学生生日
张衡是哪个朝代的人?
成都东离市中心多远,南宁火车站到南宁东站有
免费日语学习软件
可爱怎么解释?
电视购里的话能信吗?
你地下多少极了
2009sp5版本钻的问题。
关于合同中包括但不限于是什么意思
谁有什么好看的恐怖片介绍么?
CPU:AMD 羿龙X4 9650和AMD 羿龙IIX4 925那个
QQ飞车里怎么找极品装备?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?