SOS 高手救命啊!!!关于数据结构的线性表很简单100分全送

aoyunwansui8 2005-07-11 10:51:20
我正在自学严蔚敏写的数据结构 初学
感觉看了很长时间还是不懂里边的伪码怎么转变为真正的c语言
请高手指点
帮我把下边的伪码改为在 turbo c 上可以运行的c语言
我将感激不尽 谢谢大家
100分全送

----线性表的动态分配顺序存储结构----
#define LIST_INIT_SIZE 100 //线性表存储空间的初始分配量
#define LISTINCREMENT 10 //线性表存储空间的分配增量
typedef struct {
ElemType *elem; //存储空间基址
int length; //当前长度
int listsize; //当前分配的存储容量(以sizeof(Elemtype)为单位)
}SpList;

Status InitList_Sq(SqList &L){ //???c中没见过status阿
//构造一个空的线性表L
L.elem=(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L.elem)exit(OVERFLOW) //存储分配失败
L.length=0; //空表长度为0
L.listsize=LIST_INIT_SIZE //初始存储容量
return OK;
}
...全文
296 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
longtian_haidao 2005-07-17
  • 打赏
  • 举报
回复
我也正在学 严蔚敏写的数据结构
大家一起努力 哈哈
Status应该是一个 型别把
AntonlioX 2005-07-16
  • 打赏
  • 举报
回复
up
guanlicome 2005-07-16
  • 打赏
  • 举报
回复
你的笔误InitList_Sq(SpList* L)
guanlicome 2005-07-16
  • 打赏
  • 举报
回复
是这个,调试过了#include <stdlib.h>

#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10

typedef int ElemType;
typedef int Status;
#define OK 0
#define OVERFLOW -1

typedef struct {
ElemType *elem;
int length;
int listsize;
} SqList;


Status InitList_Sq(SqList& L)
{

L.elem=(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L.elem)
{
exit(0);
}
L.length=0;
L.listsize=LIST_INIT_SIZE ;
return OK;
}
int main(){return 0;}
AntonlioX 2005-07-16
  • 打赏
  • 举报
回复
up
aoyunwansui8 2005-07-16
  • 打赏
  • 举报
回复
#include <stdlib.h>

#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10

typedef int ElemType;
typedef int Status;
#define OK 0
#define OVERFLOW -1

typedef struct {
ElemType *elem;
int length;
int listsize;
}SqList;

main(){}
Status InitList_Sq(SpList* L)
{

L.elem=(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L.elem)
{
exit(0);
}
L.length=0;
L.listsize=LIST_INIT_SIZE ;
return OK;
}

为什么这样还是不能运行 说Status InitList_Sq(SpList* L) 有语法错误?????????????????????????????????????????????????????????????????????????????????????????
请高手指点
junnyfeng 2005-07-13
  • 打赏
  • 举报
回复
说status InitList_Sq(SpList* L) 有语法错误

---------
status 是个需要自己定义的类型。

如 typedef int status;
aoyunwansui8 2005-07-13
  • 打赏
  • 举报
回复
不知为什么我在turbo c 上还是运行不成功
加上main()也不行
到底是哪还有问题
请高手详细指点
说status InitList_Sq(SpList* L) 有语法错误
zhangxiaohan 2005-07-12
  • 打赏
  • 举报
回复
这是单链表的的一个例子!

创建一个存放正整数(输入- 9 9 9做结束标志)的单链表,并打印输出。

#include <stdlib.h>
#include <stdio.h>
struct node /*链表节点的结构* /
{
int num;
struct node *next;
} ;
m a i n ( )
{
struct node *creat(); / *函数声明* /
void print();
struct node *head; / * 定义头指针* /
head=NULL ; / * 建一个空表* /
head=creat(head) ; / * 创建单链表* /
print(head) ; / *打印单链表* /
}
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
struct node *creat(struct node *head) 函 /数*返回的是与节点相同类型的指针*/
{
struct node *p1,*p2;
p1=p2=(struct node*) malloc(sizeof(struct node));申 请/*新节点*/
scanf("%d",&p1->num) ; / * 输入节点的值* /
p1->next=NULL ; / * 将新节点的指针置为空* /
while(p1->num>0) / * 输入节点的数值大于0 * /
{
if (head==NULL) head=p1; / * 空表,接入表头* /
else p2->next=p1; / * 非空表,接到表尾* /
p2=p1 ;
p1=(struct node *)malloc(sizeof(struct node)); 申/请* 下一个新节点*/
scanf("%d",&p1->num ) ; / *输入节点的值* /
}
return head; /*返回链表的头指针* /
}
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
void print(struct node *head) 输/*出以he a d 为头的链表各节点的值*/
{
struct node *temp;
temp=head ; / *取得链表的头指针* /
while(temp!=NULL) / *只要是非空表* /
{
printf("%6d",temp->num) ; / *输出链表节点的值* /
temp=temp->next ; / *跟踪链表增长* /
}
}
zsx123 2005-07-12
  • 打赏
  • 举报
回复
status InitList_Sq(SpList *L)
{
//构造一个空的线性表L
L->elem=(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L->elem)
{
exit(0); //存储分配失败
}
L->length=0; //空表长度为0
L->listsize=LIST_INIT_SIZE ; //初始存储容量
return OK;
}
zsx123 2005-07-12
  • 打赏
  • 举报
回复
status InitList_Sq(SpList &L)
{
//构造一个空的线性表L
L.elem=(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L.elem)
{
exit(0); //存储分配失败
}
L.length=0; //空表长度为0
L.listsize=LIST_INIT_SIZE ; //初始存储容量
return OK;
}
改为如下(c是没有引用的 ,只能用指针了)

status InitList_Sq(SpList &L)
{
//构造一个空的线性表L
L.elem=(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L.elem)
{
exit(0); //存储分配失败
}
L.length=0; //空表长度为0
L.listsize=LIST_INIT_SIZE ; //初始存储容量
return OK;
}
zsx123 2005-07-12
  • 打赏
  • 举报
回复
#include <malloc.h>
#include <stdlib.h>

#define LIST_INIT_SIZE 100 //线性表存储空间的初始分配量
#define LISTINCREMENT 10 //线性表存储空间的分配增量

#define ElemType int
#define OVERFLOW 0 //堆分配失败
#define OK 1 //堆分配成功
#define status int

typedef struct
{
ElemType *elem; //存储空间基址
int length; //当前长度
int listsize; //当前分配的存储容量(以sizeof(Elemtype)为单位)
}SpList;

status InitList_Sq(SpList &L)
{
//构造一个空的线性表L
L.elem=(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L.elem)
{
exit(0); //存储分配失败
}
L.length=0; //空表长度为0
L.listsize=LIST_INIT_SIZE ; //初始存储容量
return OK;
}
popcom 2005-07-12
  • 打赏
  • 举报
回复
up
jixingzhong 2005-07-12
  • 打赏
  • 举报
回复
#include <stdlib.h>

#define LIST_INIT_SIZE 100 //线性表存储空间的初始分配量
#define LISTINCREMENT 10 //线性表存储空间的分配增量

typedef int ElemType;
typedef int Status;
#define OK 0
#define OVERFLOW -1

typedef struct {
ElemType *elem; //存储空间基址
int length; //当前长度
int listsize; //当前分配的存储容量(以sizeof(Elemtype)为单位)
}SqList;


status InitList_Sq(SpList* L) //用指针!!
{
//构造一个空的线性表L
L.elem=(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L.elem)
{
exit(0); //存储分配失败
}
L.length=0; //空表长度为0
L.listsize=LIST_INIT_SIZE ; //初始存储容量
return OK;
}
Willpro 2005-07-12
  • 打赏
  • 举报
回复
status InitList_Sq(SpList &L)
{
//构造一个空的线性表L
L.elem=(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L.elem)
{
exit(0); //存储分配失败
}
L.length=0; //空表长度为0
L.listsize=LIST_INIT_SIZE ; //初始存储容量
return OK;
}
改为如下(c是没有引用的 ,只能用指针了)

status InitList_Sq(SpList &L)
{
//构造一个空的线性表L
L.elem=(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L.elem)
{
exit(0); //存储分配失败
}
L.length=0; //空表长度为0
L.listsize=LIST_INIT_SIZE ; //初始存储容量
return OK;
}
zhousct 2005-07-11
  • 打赏
  • 举报
回复
up
搬不搬砖 2005-07-11
  • 打赏
  • 举报
回复
#include <stdlib.h>

#define LIST_INIT_SIZE 100 //线性表存储空间的初始分配量
#define LISTINCREMENT 10 //线性表存储空间的分配增量

typedef int ElemType;
typedef int Status;
#define OK 0
#define OVERFLOW -1

typedef struct {
ElemType *elem; //存储空间基址
int length; //当前长度
int listsize; //当前分配的存储容量(以sizeof(Elemtype)为单位)
}SqList;

Status InitList_Sq(SqList &L){ //???c中没见过status阿
//构造一个空的线性表L
L.elem=(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L.elem)exit(OVERFLOW); //存储分配失败
L.length=0; //空表长度为0
L.listsize=LIST_INIT_SIZE; //初始存储容量
return OK;
}

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧