| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1073 人关注过本帖
标题:顺序表的插入问题
只看楼主 加入收藏
slowlybear
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2006-10-18
收藏
 问题点数:0 回复次数:2 
顺序表的插入问题

#include "stdlib.h"
#include "stdio.h"
#define MAX 100

struct SeqList
{
int date[MAX];
int length;
} //定义顺序表
typedef struct SeqList *PSeqList;

PSeqList creatSeqList(void)
{
PSeqList SeqListPoint;
SeqListPoint=(PSeqList)malloc(sizeof(struct SeqList));
if (SeqListPoint)
SeqListPoint.length=0;
return (SeqListPoint);
} //创建顺序表;

void DestorySeqList(PSeqlist *SeqListPoint)
{
if (*SeqListPoint)
free (*SeqListPoint);
*SeqListPoint=NULL;
return;
} //销毁顺序表;

int insertSeqList(PSeqlist *SeqListPoint,int i,int x) //表,位置,数字
{
int j;
if (!SeqlistPoint)
{
printf("There is no the list!");
return (-2);
}
if (SeqListPoint.length>=MAX)
{
printf("There is no vacantness!");
return (-1);
}
if ((i<1)||(i>SeqListPoint.length+1)
{
printf("Here can not be inserted!");
return (0);
}
for (j=SeqListPoint.length-1;j>=i-1;j--)
SeqListPoint.date[j+1]=SeqListPoint.date[j];
SeqListPoint.date[i-1]=x;
SeqListPoint.length++;
return (1);
} //顺序表插入


main()
{
PSeqList list;
int i,place,num;
list=creatSeqList();
printf("Where you want to insert and What's number:");
scanf("%d,%d",place,num);
for (i=0;i<=10;i++)
{
list.length++;
list.date[i]=i;
}
for (i=0;i<=list.length-1;i++)
printf("%d ",list.date[i]);
insertSeqList(list,place,num);
for (i=0;i<=list.length-1;i++)
printf("%d ",list.date[i]);
DestorySeqList(list);
}



我学的是C数据结构,而用的是VC++6。0环境,因为这个编起来舒服一些```

这个程序在VC++6。0下没有报错和警告,可是运行就说“程序无法执行”,郁闷半天。
而老师给的程序却可以顺利通过。

请指点一下!

搜索更多相关主题的帖子: 顺序表 SeqListPoint PSeqList struct void 
2007-06-26 16:42
slowlybear
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2006-10-18
收藏
得分:0 
如果在TC环境下的话,把所有//去掉以后,不能通过编译。
问题如下:
1.typedef struct SeqList *PSeqList; //此行出现"Too many types in declaration"
2.SeqListPoint.length=0; //此为创建顺序表中的一句,出现错误"Illegal structure operation in function creatSeqList"
如果把"."换成"->"问题消失,不过这两个在书上说功能一样啊,何解?

3.void DestorySeqList(PSeqlist *SeqListPoint) //此行出现"Argument list syntax error"

请大家帮忙

2007-06-26 16:57
無邪的睡脸
Rank: 2
等 级:等待验证会员
威 望:1
帖 子:344
专家分:13
注 册:2007-9-11
收藏
得分:0 

错误1是结构体定义后少了分号v;
错误2v:SeqListPoint是指针类型,要么用->,要么用(*SeqListPoint).length=0
至于错误3:实在不知怎么说了,害我找了半天,PSeqlist中的l要大写,建议以后不要大小写混在一起了!真麻烦!
下面还有很多这样的错误你没发现吗?我都帮你一一改过来了!现在编译没错了!你运行下看:我运行成功!在vc6.0下
#include "stdlib.h"
#include "stdio.h"
#define MAX 100

struct SeqList
{
int date[MAX];
int length;
};
typedef struct SeqList *PSeqList;

PSeqList creatSeqList(void)
{
PSeqList SeqListPoint;
SeqListPoint=(PSeqList)malloc(sizeof(struct SeqList));
if(SeqListPoint!=NULL)
(*SeqListPoint).length=0;
return SeqListPoint;
}

void DestorySeqList(PSeqList SeqListPoint)
{
if(SeqListPoint)
free(SeqListPoint);
SeqListPoint=NULL;
return;
}

int insertSeqList(PSeqList SeqListPoint,int i,int x) //表,位置,数字
{
int j;
if (SeqListPoint==NULL)
{
printf("There is no the list!");
return (-2);
}
if (SeqListPoint->length>=MAX)
{
printf("There is no vacantness!");
return (-1);
}
if ((i<1)||(i>SeqListPoint->length+1))
{
printf("Here can not be inserted!");
return (0);
}
for (j=SeqListPoint->length-1;j>=i-1;j--)
SeqListPoint->date[j+1]=SeqListPoint->date[j];
SeqListPoint->date[i-1]=x;
SeqListPoint->length++;
return 1;
} //顺序表插入

int main()
{
PSeqList list;
int i,place,num;
list=creatSeqList();
printf("Where you want to insert and What's number:");
scanf("%d%d",&place,&num);
for(i=0;i<10;i++)
{
list->length++;
list->date[i]=i+1;
}
for(i=0;i<=list->length-1;i++)
printf("%d\t",list->date[i]);
printf("\n");
insertSeqList(list,place,num);
for(i=0;i<=list->length-1;i++)
printf("%d\t",list->date[i]);
printf("\n");
DestorySeqList(list);
return 0;
}

[此贴子已经被作者于2007-9-27 9:28:49编辑过]

2007-09-27 09:01
快速回复:顺序表的插入问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018083 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved