moluuser's Blog - 数据结构
type: channel
link: https://archive.moluuser.com/tag/数据结构
items: 数据结构总结

数据结构总结
type: item
date: 2021-05-20T23:09:00+00:00
description: 0 思维导图https://file.moluuser.com/mind/ds.html1 线性表线性表的顺序存储结构//线性表的顺序存储结构 # include <stdio.h> # define OK 1 # define ERROR 0 # define TRUE 1 # define FALSE 0 # define MAXSIZE 20 typedef int Status; typedef int ElemType; typedef struct { ElemType data[MAXSIZE]; int length; } SqList; //获得元素操作 Status GetElem(SqList L, int i, ElemType *e) { if (L.length == 0 || i < 1 || i > L.length) return ERROR; *e = L.data[i - 1]; return OK; } //插入操作 //在第i个位置之前插入新的数据元素e，L的长度加1 Status ListInsert(SqList *L, int i, ElemType e) { int k; if (L->length == MAXSIZE) return ERROR; if (i < 1 || i > L->length + 1) return ERROR; // 插入的位置不在表尾 if (i <= L->length) { // 将要插入位置后数据元素向右移动一位 for (k = L->length - 1; k >= i - 1; k--) { L->data[k + 1] = L->data[k]; } } L->data[i - 1] = e; L->length++; return OK; } //删除操作 //删除L的第i个数据元素，并用e返回其值，L的长度减1 Status ListDelete(SqList *L, int i, ElemType *e) { int k; if (L->length == 0) return ERROR; if (i < 1 || i > L->length) return ERROR; *e = L->data[i - 1]; if (i < L->length) { for (k = i, k < L->length; k++) { L->data[k - 1] = L->data[k]; } } L->length--; return OK; } int main() { return 0; }线性表的链式存储结构//线性表的链式存储结构 # include <stdio.h> # include <stdlib.h> # include <time.h> # define OK 1 # define ERROR 0 # define TRUE 1 # define FALSE 0 typedef int Status; typedef int ElemType; typedef struct Node { ElemType data; struct Node *next; } Node; typedef struct Node *LinkList; //读取第i个元素的值 Status GetElem(LinkList L, int i, ElemType *e) { int j; LinkList p; p = L->next; j = 1; while (p && j < i) { p = p->next; ++j; } if (!p || j > i) return ERROR; *e = p->data; return OK; } //单链表的插入 //在L中第i个结点位置之前插入新的数据元素e Status ListInsert(LinkList *L, int i, ElemType e) { int j; LinkList p, s; p = *L; j = 1; // 寻找第i-1个结点 while (p && j < i) { p = p->next; ++j; } if (!p || j > i) return ERROR; s = (LinkList)malloc(sizeof(Node)); s->data = e; s->next = p->next; p->next = s; return OK; } //单链表的删除 //删除L的第i个结点 Status ListDelete(LinkList *L, int i, ElemType *e) { int j; LinkList p, q; p = *L; …