C语言定义code报错,C语言数据结构初学者,codeblocks报错

修改了语法错误,至少可以编译通过#include 

#include 

#include 

#define TRUE1

#define FALSE0

#define OK1

#define ERROR0

#define INFEASIBLE-1

#define OVERFLOW-2

#define list_init_size100

/* 线性表存储空间的初始分配量 */

#define LISTINCREMENT 10

/* 线性表存储空间的分配增量 */

typedef intStatuss;

typedef intElemType;

typedef struct {

ElemType *elem;

/* 存储空间基址 */

int length;

/* 当前长度 */

int listsize;

/* 当前分配的存储容量(以sizeof(ElemType)为单位) */

}SqList;

int InitList_Sq( SqList L )

{

/* 构造一个空的线性表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);

};

/* Initlist_Sq */

int ListInsert_Sq( SqList L, int i, ElemType e )

{

/*

* 在顺序线性表L中第i个位置之前插入新的元素e,

* i的合法值为1<=i<=ListLength_Sq(L)+1

*/

ElemType *p, *q, *newbase;

/* 定义指针 */

if ( i  L.length + 1 )

return(ERROR);

/* i值不合法 */

if ( L.length >= L.listsize )

{

/* 当前存储空间已满,增加分配 */

newbase = (ElemType * ) realloc( L.elem, (L.listsize + LISTINCREMENT) * sizeof(ElemType) );

if ( i <= L.length )

return(i);

else return(0);

}

}

/* LocateElem_Sq */

void MergeList_Sq( SqList La, SqList Lb, SqList Lc )

{

/*

* 已知顺序线性表La和Lb的元素按值非递减排列

* 归并La和Lb得到新的顺序线性表Lc,Lc的元素也按非递减排列

*/

ElemType *pa, *pb, *pc, *pa_last, *pb_last;

pa= La.elem;

pb= Lb.elem;

Lc.listsize= Lc.length = La.length + Lb.length;

pc= Lc.elem = (ElemType *) malloc( Lc.listsize * sizeof(ElemType) );

if ( !Lc.elem )

exit( OVERFLOW );  /* 存储分配失败 */

pa_last = La.elem + La.length - 1;

pb_last = Lb.elem + Lb.length - 1;

while ( pa <= pa_last && pb <= pb_last )

{

/* 归并*/

if(*pa<=*pb)

*pc++ = *pa++;

else

*pc++ = *pb++;

}

while ( pa <= pa_last )

*pc++ = *pa++;

/* 插入La的剩余元素 */

while ( pb <= pb_last )

*pc++ = *pb++;

/* 插入Lb的剩余元素 */

}

/* MergeList_Sq */

void main()

{

SqList La, Lb, Lc;

InitList_Sq( La );

ListInsert_Sq( La, 1, 3 );

ListInsert_Sq( La, 2, 5 );

ListInsert_Sq( La, 3, 8 );

ListInsert_Sq( La, 4, 11 );

printf( "La插入后:\n" );

//display( La );

InitList_Sq( Lb );

ListInsert_Sq( Lb, 1, 2 );

ListInsert_Sq( Lb, 2, 6 );

ListInsert_Sq( Lb, 3, 8 );

ListInsert_Sq( Lb, 4, 9 );

ListInsert_Sq( Lb, 5, 11 );

ListInsert_Sq( Lb, 6, 15 );

ListInsert_Sq( Lb, 7, 20 );

printf( "Lb插入后:\n" );

//display( Lb );

MergeList_Sq( La, Lb, Lc );

printf( "归并后:\n" );

//display( Lc );

printf( "\n" );

//int a = LocateElem_Sq( Lc, 5 );

//printf( "%d\n", a );

}

温馨提示:答案为网友推荐,仅供参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值