当前位置:网站首页>(1), the sequential storage structure of linear table chain storage structure
(1), the sequential storage structure of linear table chain storage structure
2022-08-04 17:02:00 【Little Monk Hanshui Temple Wuxin】
一、前言
This book combines Cheng Jie's《大话数据结构》learning from a book.I have forgotten a lot of the data structure knowledge I learned before,Reread it recently.No theoretical knowledge is involved,Mainly code implementation.
二、线性表
线性表:0个或多个数据元素的有限序列.
线性表的抽象数据类型:顺序存储结构、链式存储结构
A sequential storage structure for a linear list,指的是用一段地址连续的存储单元依次存储线性表的数据元素.
三、线性表的顺序存储结构
线性表的顺序存储代码:
#define MAXSIZE 20
typedef char ElemType;
typedef struct{
ElemType data[MAXSIZE];
int length;
}SqList;
#define OK 1
#define ERROR 0
typedef int Status;
//获取元素
Status GetElem(SqList L, int i, ElemType *e)
{
if(L.length <= 0)
return ERROR;
if((i <= 0) || (i > L.length))
return ERROR;
*e = L.data[i-1];
return OK;
}
//插入
Status ListInsert(SqList *L, int i; ElemType e)
{
int k;
if(!L || (i <= 0) || (i>L->length +1))
return ERROR;
if(L->length == MAXSIZE)
return ERROR;
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;
}
//删除
Status ListDelete(SqList *L, int i, ElemType *e)
{
int k;
if(!L || (i<1) || (i>L->length))
{
return ERROR;
}
*e = L->data[i-1];
for(k = i-1; k < L->length - 1; k++)
{
L->data[k] = L->data[k+1];
}
L->length--;
return OK;
}
四、线性表的链式存储结构
#define OK 1
#define ERROR 0
typedef int ElemType;
typedef struct Node{
ElemType data;
struct Node *next;
}Node;
typedef struct Node *LinkList;
#include <stdio.h>
#include "linklist.h"
//获取第iThe data field value of a node
Status GetElem(LinkList L, int i, ElemType *e)
{
int j;
LinkList p;
p = L->next;
if(i<1)
return ERROR;
j = 1;
while(p && j <i)
{
p = p->next;
j++;
}
if(!p)
return ERROR;
*e = p->data;
return OK;
}
Status ListInsert(LinkList *L, int i, ElemType e)
{
int j = 1;
LinkList p, s;
p = *L;
if(!L || i < 0)
return ERROR;
while(p || j < i)
{
p = p->next;
j++;
}
if(!p)
return ERROR;
s = (LinkList)malloc(sizeof(Node))
s->data = e;
s->next = p->next;
p-next = s;
return OK;
}
Status ListDelete(LinkList *L, int i, ElemType *e)
{
int j = 1;
LinkList p, q;
p = *L;
if(!L || i < 1)
return ERROR;
while(p->next || j < i)
{
p = p->next;
j++;
}
if(!p->next)
return ERROR;
q = p->next;
p->nex = q->next;
*e = q->data;
free(q);
return OK;
}
边栏推荐
- 黑龙江移动新魔百盒M411A_2+8_S905L3A_线刷固件包
- 谷粒商城笔记
- dotnet core 隐藏控制台
- nyist 301 递推求值(矩阵快速幂)
- 开一个羽毛球馆大概需要多少钱?大约15万左右可以搞定!
- "Distributed cloud best practices" BBS, on August 11, shenzhen
- pygame的freetype模块
- 安装win11提示开启安全模式如何解决
- 力拓信创生态,博睿数据多款产品获得东方通与达梦数据库产品兼容互认证明
- Copycat CNN: Stealing Knowledge by Persuading Confession with Random Non-Labeled Data阅读心得
猜你喜欢

15 days to upgrade to fight monsters and become a virtual fashion creator

Mobile magic box CM201-1_CW_S905L2_MT7668_wire brush firmware package

Selenium Webdriver驱动自管理

Mobile BesTV_R3300-L_S905L_8189_wire brush firmware package

从云计算到函数计算

win11如何退出安全模式

学习探索-网站中引入百度统计

移动魔百盒CM211-1_YS代工_S905L3B_RTL8822C_线刷固件包

Hubei Mobile HG680-LV_S905L3B_wire brush firmware package

Hubei Mobile ZTE B860AV2.1_S905L_ flash firmware package
随机推荐
【Gazebo入门教程】第二讲 模型库导入与可视化机器人建模(模型编辑器)
Copycat CNN: Stealing Knowledge by Persuading Confession with Random Non-Labeled Data阅读心得
码蹄集 - MT2142 - 万民堂大厨
容器化 | 在 NFS 备份恢复 RadonDB MySQL 集群数据
WEB 渗透之越权
泰坦尼克号沉船数据之美——起于悲剧,止于浪漫
重新审视分布式系统:永远不会有完美的一致性方案……
拼多多详情API接口深度解读
麒麟信安石勇博士荣获openEuler社区年度开源贡献之星
icu是哪个国家的域名?icu是什么域名?
全世界国家和地区国家顶级域名对照表
智慧场馆的功能有哪些
LeetCode 1403.非递增顺序的最小子序列
【笔试题】-【日常记录】
智慧场馆的无人值守怎么做?
浙江数码代工M301H 免拆通刷_卡刷固件包(语音OK)
码蹄集 - MT2094 - 回文之时:第4组数据错误
一张图片怎么旋转90度。利用ps
15 days to upgrade to fight monsters and become a virtual fashion creator
机器学习(十八):随机搜索和XGBoost