当前位置:网站首页>Definition and Basic Operations of Linear Tables
Definition and Basic Operations of Linear Tables
2022-08-09 22:07:00 【never stop..】
线性表的定义:
线性表是具有相同数据类型[Each data element occupies the same space]的n(n>=0)个数据元素的有限序列[The elements in the table must be finite,and arranged in a certain order],其中n为表长,当n=0时线性表是一个空表,若用L命名线性表,则一般表示为:L=(a1,a2…ai,ai+1…an)
注:
ai是线性表中的‘第i个’元素线性表中的位序[位序是从1开始,Array subscripts are zero-based]
a1是表头元素,an是表尾元素
除第一个元素外,每个元素有且仅有一个直接前驱,除最后一个元素外,每个元素有且仅有一个直接后继.
线性表的基本操作:
lnitList(&L):初始化表.构造一个空的线性表L,分配内存空间.
DestroyList(&L):销毁操作.销毁线性表,并释放线性表L所占用的内存空间.
Listlnsert(&L,i,e):插入操作.在表L中第i个位置上,插入元素e.
ListDelete(&L,i,&e):删除操作.删除表中第i个位置上的元素,并用e返回删除元素的值.
LocateElem(L,e):按值查找操作.在表L中查找具有给定关键字值的元素.
GetElem(L,i):按位查找操作.获取表L中第i个位置元素的值
其他常见操作:
length(L):求表长.返回线性表L的长度,即L中数据元素的个数.
PrintList(L):输出操作.Output the linear table in sequential orderL的所有元素的值.
Empty(L):判空操作.若L为空表,则返回True,否则返回False.
注:
Function name and parameter form,Nomenclature can be changed,But the naming must be readable.
什么时候要传入参数的引用“&”?-----对参数的修改结果需要“传递回来”
举例:
#include<stdio.h>
void test(int x)
{
x = 1024;
printf("test函数内部 x=%d\n", x);
}
int main()
{
int x = 1;
printf("调用test前 x=%d\n", x);
test(x);
printf("调用test后 x=%d\n", x);
return 0;
}
通过输出结果,We'll find out even when calledtest函数,但xThe value remains unchanged,The reason is in the process of function call,我们传递给test函数的是x的值,在testThe value is modified inside the function,This operation is onlytest函数内部生效,But in fact the data is not really modified,So returned to the main functionxThe value is still the value before the modification,有点类似于CPass-by-value and pass-by-address issues in the pointer part of the language.
To achieve cross-function modification,就要使用"&"引用
修改如下:
#include<stdio.h>
void test(int *x)
{
*x = 1024;
printf("test函数内部 x=%d\n", *x);
}
int main()
{
int x = 1;
printf("调用test前 x=%d\n", x);
test(&x);
printf("调用test后 x=%d\n", x);
return 0;
}
输出如下:
The reason for implementing the operation on the data structure:
团队合作编程,The data structures we define are meant to be more than just usable
将常用的操作/运算封装成函数,避免重复工作,降低出错的风险
边栏推荐
- 华为云全流程护航《流浪方舟》破竹首发,打造口碑爆款
- buuctf (Adventure 2)
- 【kali-密码攻击】(5.1.1)密码在线破解:Hydra(图形界面)
- pytest框架之mark标记功能详细介绍
- Next second data: the transformation of the modern data stack brought about by the integration of lake and warehouse has begun
- 面试官:Redis 大 key 要如何处理?
- 数据分散情况的统计图-盒须图
- [] free column Android dynamic debugging GDB APP of safety
- Why is the data of maxcompute garbled when imported into mysql?The table of mysql is the encoding of udf8mb4
- 嵌入式开发:使用FILL提高代码完整性
猜你喜欢
《评估、创建和使用知识图谱的限制》2022最新230页博士论文,根特大学
IS31FL3737B 通用12×12 LED驱动器 I2C 42mA 40QFN
毕昇编译器优化:Lazy Code Motion
visual studio 2022调试技巧介绍
Acrel5000web能耗系统在某学院的应用-Susie 周
钢材行业供应链协同管理系统提升企业上下游密切度,精细化企业内部管理
[Free column] Xposed plug-in development for Android security [from scratch] tutorial
IS31FL3737B general 12 x 12 LED drive 40 QFN I2C 42 ma
字节一面:TCP 和 UDP 可以使用同一个端口吗?
小满nestjs(第三章 前置知识装饰器)
随机推荐
鲜花线上销售管理系统的设计与实现
如何在WPF中设置Grid ColumnDefinitions的样式
华为云全流程护航《流浪方舟》破竹首发,打造口碑爆款
智能家居设备安全分析技术综述
mysql duplicate data group multiple latest records
Prometheus Operator 通过additional 添加target
新出现的去中心化科学能够为科学领域带来什么?
IS31FL3737B 通用12×12 LED驱动器 I2C 42mA 40QFN
php删除字符串的空格
Abbkine TraKine Pro 活细胞微管染色试剂盒重要特色
渗透测试-对新型内存马webshell的研究
数学建模代码速成~赛前一个月~matlab~代码模板~吐血总结~三大模型代码(预测模型、优化模型、评价模型)
CMake installation upgrade higher version
基于网络数据流的未知密码协议逆向分析
【kali-密码攻击】(5.1.1)密码在线破解:Hydra(图形界面)
ebook下载 | 《 企业高管IT战略指南——企业为何要落地DevOps》
Acrel5000web能耗系统在某学院的应用-Susie 周
DSPE-PEG-PDP,DSPE-PEG-OPSS,磷脂-聚乙二醇-巯基吡啶可减少肽的免疫原性
[Deep learning] pix2pix GAN theory and code implementation
Cholesterol-PEG-Thiol,CLS-PEG-SH,胆固醇-聚乙二醇-巯基用于改善溶解度