- 3
- 0
- 约6.65千字
- 约 7页
- 2016-06-30 发布于贵州
- 举报
顺序存储结构线性表本操作_纯C语言实现
/////////////////////////////////////////////////////////// //--------------------------------------------------------- //??????????? 顺序存储结构线性表基本操作 纯C语言实现 // //??????????? a simple example of Sq_List by C language // //??????????????????? by wangweinoo1[PG] //--------------------------------------------------------- /////////////////////////////////////////////////////////// #include stdio.h #include stdlib.h//以下为函数运行结果状态代码 #define TRUE 1#define FALSE 0#define OK 1 #define ERROR 0 #define INFEASIBLE -1 #define OVERFLOW -2 #define LIST_INIT_SIZE 5? //线性表存储空间的初始分配量 #define LISTINCREMENT 1? //线性表存储空间分配增量 typedef int Status; //函数类型,其值为为函数结果状态代码 typedef int ElemType; //假设数据元素为整型 typedef struct { ??? ElemType *elem; //存储空间基址 ??? int length; //当前长度 ??? int listsize; //当前分配的存储容量 }Sqlist; //实现线性表的顺序存储结构的类型定义/*static*/ Sqlist L;//为了引用方便,定义为全局变量/*static*/ ElemType element;Status InitList(Sqlist L);
Status DestroyList(Sqlist L);
Status ClearList(Sqlist L);Status ListEmpty(Sqlist L);Status ListLength(Sqlist L);
Status GetElem(Sqlist L,int i, ElemType *element);
Status LocationElem(Sqlist L,ElemType element);
Status PriorElem(Sqlist L,ElemType cur_e,ElemType *pre_e);
Status NextElem(Sqlist L,ElemType cur_e,ElemType *next_e);
Status ListInsert(Sqlist L,int i,ElemType e);Status ListDelet(Sqlist L,int i,ElemType e);/////////////////////////////////////////函数名:InitList()//参数:SqList L//初始条件:无//功能:构造一个空线性表//返回值:存储分配失败:OVERFLOW//??????? 存储分配成功:OK///////////////////////////////////////Status InitList(Sqlist L){??? L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));??? if(L.elem==NULL)??????? exit(OVERFLOW);??? else??? {??????? L.length=0;??????? L.listsize=LISTINCREMENT;??????? return OK;??? }}/////////////////////////////////////////函数名:DestroyList()//参数:SqList L//初始条件:线性表L已存在//功能:销毁线性表//返回值:L.elem==NULL:ERROR//??????? L.elem!==NULL:OK///////////////////////////////////////Status DestroyList(Sqlist L){???
您可能关注的文档
最近下载
- 中学生交通安全教育培训课件PPT.pptx VIP
- 牵引供电系统 牵引变电所供电方式 牵引变电所供电方式.ppt VIP
- 1.03 玉米高产管理技术 - (先锋克劳森).pptx VIP
- 杜邦公司讲座杜邦安全管理介绍.pptx VIP
- 2025年广西财经学院辅导员招聘考试笔试模拟试题及答案解析.docx VIP
- (正式版)DB65∕T 3611-2023 《农业用水定额》.pdf VIP
- 2025年江苏省南京市中考英语试卷(含解析).pdf VIP
- (2025年版)国家基层高血压防治管理指南PPT课件.pptx VIP
- 2024年山东交通职业学院高职单招(英语/数学/语文)笔试题库含答案解析.docx VIP
- 2017年-2022年暨南大学考研701美学原理真题.pdf
原创力文档

文档评论(0)