数据结构C语言版线性表源代码

上传人:宝路 文档编号:23508714 上传时间:2017-12-01 格式:DOC 页数:6 大小:31.51KB
返回 下载 相关 举报
数据结构C语言版线性表源代码_第1页
第1页 / 共6页
数据结构C语言版线性表源代码_第2页
第2页 / 共6页
数据结构C语言版线性表源代码_第3页
第3页 / 共6页
数据结构C语言版线性表源代码_第4页
第4页 / 共6页
数据结构C语言版线性表源代码_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《数据结构C语言版线性表源代码》由会员分享,可在线阅读,更多相关《数据结构C语言版线性表源代码(6页珍藏版)》请在金锄头文库上搜索。

1、#include #include #include #include #define LIST_INIT_SIZE 100#define LISTINCREMENT 10#define OK 1#define ERROR -1#define OVERFLOW -1#define ENDFLAG 0typedef int Status;typedef int ElemType;#define OUTFORMAT %d #define INFORMAT %dtypedef structElemType *elem;int length;int listsize;SqList;Status Ini

2、tList(SqList *L)L-elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType);if(!L-elem) / 如果没有分配成功exit(OVERFLOW); /退出,显示()内内容L-length=0;L-listsize=LIST_INIT_SIZE;return OK;Status Inputdata(SqList *L) /SqList *L 定义首节点的地址ElemType temp,*newbase;printf(nInput the data of the sequencial list:nNote:0 is the

3、 ending flag:n);scanf(INFORMAT,&temp);while(temp!=ENDFLAG)if(L-length=L-listsize)newbase=(ElemType *)realloc(L-elem, (L-listsize+LISTINCREMENT)*sizeof(ElemType);/扩大空间,把旧的地址拷贝到新空间if(!newbase) exit(OVERFLOW);L-elem=newbase;L-listsize+=LISTINCREMENT;L-elemL-length+=temp;scanf(INFORMAT,&temp);return OK;

4、Status ListInsert(SqList *L,int i,ElemType e)ElemType *p,*q,*newbase;if(iL-length)return ERROR;if(L-length=L-listsize) Newbase =( elemType*)realloc(L-elem,(L-listsize+LISTINCREMENT)*sizeof(ElemType);if(!newbase) exit(OVERFLOW);L-elem=newbase; L-listsize+=LISTINCREMENT;q=&(L-elemi-1);for(p=&(L-elemL-

5、length-1);p=q;-p)*(p+1)=*p;*q=e;+L-length;return OK;void MyDisplay(SqList L)int i;for(i=0;iL.length;i+)printf(OUTFORMAT,L.elemi);printf(n);void main(void)SqList L;ElemType temp;int i;if(!InitList(&L) /如果初始化失败 printf(To initialize the sequencial list failn);getch(); /如果失败,按任意键退出exit(0);if(!Inputdata(&L)printf(To input the data of the sequencial list failn);getch();exit(0);MyDisplay(L);printf(Input the data that you want to insert:);scanf(INFORMAT,&temp);printf(Input the insert_location:);scanf(%d,&i);if(!ListInsert(&L,i,temp)printf(To insert failn);getch();exit(0);MyDisplay(L);getch();

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号