jingyuan 发布留言 2008-10-8 13:31
顺序表问题请人帮忙
建立自己的myseqlist.h文件,内容包括顺序表的描述,顺序表的查询,插入,删除,顺序表的建立与输出功能.
编写算法,通过调用中的相关函数,完成顺序表中指定位置数据的输出、元素的插入和删除操作。
数据结构真难啊,班里没人作出来。
nuciewth 发布留言 2008-10-8 13:32
那就找别的班上的。[em02]
很远的那颗星 发布留言 2008-10-8 15:03
请不要听人说难,就自已也说他难...你连顺序表都不想写,可见,你根本没见过难的..
jingyuan 发布留言 2008-10-8 17:37
我自己也编写了,调试好久,还是有错误。 帮我看看我的程序吧
# define maxsize 30
# define datatype int
typedef struct
{
datatype data [maxsize];
int last;
}SEQLIST;
SEQLIST *init_seqlist()
{
SEQLIST *L;
L=(SEQLIST *)malloc(sizeof(SEQLIST));
L->last=0;
return L;
}
void shu(SEQLIST *L)
{
int i, j, k;
printf("please input the data,end of -99\n");
j=0;
k=1;
scanf("%d",&i);
while(i!=-99&&j
{
j++;
L->data[k]=i;
k++;
scanf("%d",&i);
}
}
void chu(SEQLIST *L)
{
int k;
for(k=1;K
last;k++)
printf("%d", L->data[k]);
}
int ins_seqlist(SEQLIST *L,int i,int x)
{ int j;
if(L->last==MAXSUZE){
printf("biao man");return(-1);}
if(i<1||i>L->last+1){
printf("wei zhi cuo");return(0);}
for(j=L->last;j>=i;j--)
L->data[j]=L->data[j-1];
L->data=x;
L->last++;
return(1);
}
#include "myl.h"
#include
main()
{
SEQLIST *L;
datatype x;
int i,j;
L=init_seqlist();
shu(L);
chu(L); 提示的错误:undefined symbol'_chu'in module SL.c
}很远的那颗星 发布留言 2008-10-8 17:53
可以了,你看一下有什么不同:
#include #include # define maxsize 30 # define datatype int typedef struct { datatype data [maxsize]; int last; }SEQLIST; SEQLIST *init_seqlist() { SEQLIST *L; L=(SEQLIST *)malloc(sizeof(SEQLIST)); L->last=0; return L; } void shu(SEQLIST *L) { int i, j, k; printf("please input the data,end of -99\n"); j=0; k=0; //.......................................... scanf("%d",&i); while(i!=-99&&j { j++; L->data[k]=i; k++; L->last++; //...................................... scanf("%d",&i); } } void chu(SEQLIST *L) { for(int k=0;klast;k++) //....................... printf("%d ", L->data[k]); } int ins_seqlist(SEQLIST *L,int i,int x) { int j; if(L->last==maxsize){ //......................... printf("biao man");return(-1);} if(i<1||i>L->last+1){ printf("wei zhi cuo");return(0);} for(j=L->last;j>=i;j--) L->data[j]=L->data[j-1]; L->data=x; L->last++; return(1); }
//#include "myl.h" //......................
int main() { SEQLIST *L; //datatype x; //下面两行没有用,要来干吗? //int i,j; L=init_seqlist(); shu(L); chu(L); //... ......... system("pause"); return 0; }
|
很远的那颗星 发布留言 2008-10-8 17:55
很多语法错误,你 C 基本功还要多学一下...应该学会自已怎么处理语法错误..
很多逻辑上的东西可以上来讨论一下..jingyuan 发布留言 2008-10-8 18:11
还是提示那个错误,我用的是TurboC很远的那颗星 发布留言 2008-10-8 18:27
我的GCC通过编译,运行成功...
TC没用过,你也可能换编译器了.....jingyuan 发布留言 2008-10-8 19:16
没办法,作业要求用Toub
页: [1]