注册 登录
编程论坛 新人交流区

[求助]关于顺序表的创建问题

baozishi 发布于 2007-10-13 20:28, 971 次点击

程序如下:
但在VC++6.0中运行有很多错误,可以看一下么?
#include "stdio.h"
#include "string.h"
#define maxlen 50
typedef char elemtype;
elemtype SqList[maxlen];
void create(SqList L,int & n)
{
int i=1;
char ch;
while((ch=getchar())!='\n')
{
L[i]=ch;
i++;
}
n=i-1;
}

void disp(SqList L,int n)
{
for(int m=1;m<=n;m++)
printf("L[%d]=%c\n",m,L[m]);
printf("n=%d\n",n)
}
void main(int argc,char * argv[])
{
Sqlist L;
int n;
create(L,n);
disp(L,n);

}

5 回复
#2
时间尘埃2007-10-13 20:36
Sqlist L;

elemtype SqList[maxlen];
SqList 是数组名,你怎么用它来定义新数据呢?它可不是数据类型啊.
#3
baozishi2007-10-13 20:46

#include "stdio.h"
#include "string.h"

void create(char L[],int & n)
{
int i=1;
char ch;
while((ch=getchar())!='\n')
{
L[i]=ch;
i++;
}
n=i-1;
}

void disp(char L[],int n)
{
for(int m=1;m<=n;m++)
printf("L[%d]=%c\n",m,L[m]);
printf("n=%d\n",n)
}
void main(int argc,char * argv[])
{
Sqlist L;
int n;
create(L,n);
disp(L,n);

}

#4
longfeng8672007-10-13 23:03

你 是想用结构体吧?

#5
baozishi2007-10-15 10:01
这个不是结构体的,这个是顺序表创建嘛
单链表和循环链表它们用结构体的呀...
顺序表一般用的是数组顺序存储呀...
程序大概是这样了,帮我看一下改一下哈...
#6
longfeng8672007-10-15 14:59
#include <stdio.h>//包含的头文件如果是库里面自带的最好是用"<>"
#include <string.h>
#include<stdlib.h>
#define maxlen 50
char SqList[maxlen];
int n;
void create(char L[])//建立顺序表
{
int i=1;
char ch;
while((ch=getchar())!='\n')
{
L[i]=ch;
i++;
}
n=i-1;
}
void display(char L[])//显示
{
int i;
for(i=1;i<=n;i++)
printf("L[%d]=%c\n",i,L[i]);
printf("\nn=%d\n",n);
}
void main(int argc,char * argv[])
{
create(SqList);
display(SqList);
system("pause");
}
//已修正
1