详情注释都有,下次有时间将合并写好一些
#include <stdio.h> #include <stdlib.h> //----------线性表的动态分配 顺序 存储结构------------- #define LIST_INT_SIZE 100 #define LISTINCREATMENT 10 #define OVERFLOW -2 #define OK 1 #define ERROR 0 typedef int ElemType; typedef struct { ElemType *elem; int length; int listsize; /*当前分配的存储容量*/ } SqList; SqList InitList(SqList L) { //初始化 L.elem = (ElemType *)malloc(LIST_INT_SIZE * sizeof(ElemType)); if (!L.elem) exit(OVERFLOW); L.length = 0; L.listsize = LIST_INT_SIZE; return L; } int ListInsert(SqList *L, int i, ElemType e) { //插入元素 // i 是 位置不是下标 if (i < 1 || i > (*L).length + 1) return ERROR; if (L->length >= L->listsize) // 存储空间已经满了 ,增加分配 { ElemType *newbase = (ElemType *)realloc(L->elem, (L->listsize + LISTINCREATMENT) * sizeof(ElemType)); if (!newbase)
线性表的顺序显示
最新推荐文章于 2022-09-13 22:58:25 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)