C语言数据结构--线性表(List)

1.0 线性表

 

线性表头文件:

#pragma once

#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define INVALID_INDEX -1

// 存储空间初始分配量
#define LIST_INIT_SIZE 20


// 元素类型,假定是 int 类型。
typedef int elemType;

typedef struct ListNode
{
	// 容量
	int capacity;
	// 当前长度
	int length;
	// 存储的数据类型
	elemType* data;
}SqList;

// 初始化一个列表
int initList(SqList * list, int capacity = LIST_INIT_SIZE);

// 插入元素
int insertList(SqList* list, const elemType e);

// 插入元素
int insertList(SqList * list, int index, const elemType e);

// 打印一个 list
void print(SqList* list);

// 获取一个元素
elemType getElement(SqList* list, int index, elemType* e);

// 获取一个元素下标
int getElement(SqList* list, elemType e);

// 删除
elemType removeElement(SqList* list, const elemType e);

// 删除
elemType removeElement(SqList* list, int index, elemType* e);

// 获取线性表的长度
int getListLength(SqList* list);

// 扩容 默认两倍
int expandList(SqList* list);

// 缩小
int shrink(SqList * list);


线性表实现文件:


#include"List.h"

#include 
#include 
#include 

int initList(SqList* list,int capacity)
{
	list->data = (elemType *)malloc(capacity * sizeof(elemType));
	list->capacity =

你可能感兴趣的:(C,语言数据结构,链表,列表,数据结构)