数据结构系列之一线性表

根据严蔚敏的数据结构C语言版的第二章,现在来回顾一下大学学习的数据结构知识。

 第二章   线性表

定义:一个线性表是n个数据元素的有序序列 。

抽象数据类型定义如下:

InitList(List *list);

构造一个空的线性表list。

DestroyList(List *list)

销毁线性表list。

ClearList(List *list)

将list置为空表。

ListEmpty(List list)

判断list是否为空。

ListLength(List list)

返回list中数据元素的个数。

GetElem(List list, int i, ElemType *e);

获取list中第i个元素的值e 。

LocateElem(List list, ElemType e, (int compare)());

返回list中,第一个与e满足compare关系的元素的位序。

PriorElem(List list, ElemType curr_e, ElemType *pre_e)

若curr_e是list的元素,并且不是第一个,那么返回他的前一个元素

NextElem(List list, ElemType curr_e, ElemType *next_e)

同上,返回下一个元素 

ListInsert(List *list, int i, ElemType e)

在list的第i个位置之前插入元素e

ListDelete(List *list, int i, ElemType *e)

删除list的第i个元素,并用e返回其值。 

ListTraverse(List list, (void visit)())

对list中的每个元素调用visit()。

线性表的顺序表示和实现

为了在以后方便使用一些宏定义,引入头文件types.h 

View Code 
1 //types.h
2 #define TRUE 1
3 #define FALSE 0
4 #define OK  1
5 #define ERROR 0
6 #define INFEASIBLE -1
7 #define OVERFLOW -2
8 typedef int

可以定义如下类型:

View Code 
1 #define LIST_INIT_SIZE  100
2 #define LISTINCREMENT 10 
3 typedef struct _sq_list
4 {
5      ElemType *elem;
6     int         length;
7     int         listsize; 
8 
未完待续。。。
原文地址:https://www.cnblogs.com/xingyayang/p/2080151.html