当前位置:网站首页>Basic operation of sequence table
Basic operation of sequence table
2022-04-23 04:37:00 【Two ball Sycamore】
Today, let's learn the basic operation of sequence table .
List of articles
- Preface
- One 、 Initialization sequence table
- Two 、 Print order table
- 3、 ... and 、 Destroy space
- Four 、 Check capacity space , Full capacity expansion
- 5、 ... and 、 Tail insertion
- 6、 ... and 、 Deletion at the end
- 7、 ... and 、 Head insertion
- 8、 ... and 、 Head deletion
- Nine 、 Insert... At a certain location
- Ten 、 Delete a location
- 11、 ... and 、 lookup
- Twelve 、 modify
Preface
The order sheet , Full name sequential storage structure , It's a kind of linear table .
When a sequence table stores data , Will apply for a whole piece of physical space of sufficient size in advance , And then store the data one by one , When storing, there is no gap between data elements .
emm, Isn't this an array
you 're right , The sequence table is A linear table stored as an array in computer memory .
One 、 Initialization sequence table
void SLInit(SL* ps)
{
assert(ps);
ps->a = NULL;
ps->size = ps->capacity = 0;
}
Two 、 Print order table
void SLPrint(SL* ps)
{
assert(ps);
for (int i = 0;i < ps->size;i++)
{
printf("%d ", ps->a[i]);
}
printf("\n");
}
3、 ... and 、 Destroy space
void SLDestory(SL* ps)
{
assert(ps);
if (ps->a)
{
free(ps->a);
ps->a = NULL;
}
}
Four 、 Check capacity space , Full capacity expansion
void SLCheckCapacity(SL* ps)
{
assert(ps);
if (ps->capacity == ps->size)
{
int newCapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;
SLDataType* tmp = (SLDataType*)realloc(ps->a, newCapacity * sizeof(SLDataType));
if (tmp == NULL)
{
perror("realloc");
exit(-1);
}
ps->a = tmp;
ps->capacity = newCapacity;
}
}
5、 ... and 、 Tail insertion
void SLPushBack(SL* ps,SLDataType x)
{
assert(ps);
// Check the space
SLCheckCapacity(ps);
ps->a[ps->size] = x;
ps->size++;
}
6、 ... and 、 Deletion at the end
void SLPopBack(SL* ps)
{
assert(ps);
assert(ps->size);
ps->size--;
}
7、 ... and 、 Head insertion
void SLPushFront(SL* ps,SLDataType x)
{
assert(ps);
// Check the space
SLCheckCapacity(ps);
// Move data
int end = ps->size - 1;
while (end >= 0)
{
ps->a[end + 1] = ps->a[end];
end--;
}
ps->a[0] = x;
ps->size++;
}
8、 ... and 、 Head deletion
void SLPopFront(SL* ps)
{
assert(ps);
assert(ps->size>0);
int begin = 1;
while (begin < ps->size)
{
ps->a[begin-1] = ps->a[begin];
++begin;
}
ps->size--;
}
Nine 、 Insert... At a certain location
void SLInsert(SL* ps, int pos, SLDataType x)
{
assert(ps);
assert(pos >= 0 && pos <= ps->size);
// Check the space
SLCheckCapacity(ps);
int end = ps->size-1;
while (end >= pos)
{
ps->a[end + 1] = ps->a[end];
--end;
}
ps->a[pos] = x;
ps->size++;
}
Ten 、 Delete a location
void SLErase(SL* ps, int pos)
{
assert(ps);
assert(pos >= 0 && pos < ps->size);
int begin = pos;
while (begin < ps->size-1)
{
ps->a[begin] = ps->a[begin + 1];
++begin;
}
ps->size--;
}
11、 ... and 、 lookup
int SLFind(SL* ps, SLDataType x)
{
assert(ps);
for (int i = 0; i < ps->size; i++)
{
if (x == ps->a[i])
return i;
}
return -1;
}
Twelve 、 modify
int Modify(SL* ps, int pos, SLDataType x)
{
assert(ps);
assert(pos >= 0 && pos < ps->size);
ps->a[pos] = x;
}
版权声明
本文为[Two ball Sycamore]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230407343803.html
边栏推荐
- C语言常用字符串处理函数
- Redis 命令大全
- Gut liver axis: host microbiota interaction affects hepatocarcinogenesis
- 【BIM+GIS】ArcGIS Pro2. 8 how to open Revit model, Bim and GIS integration?
- win10, mysql-8.0.26-winx64.zip 安装
- How to regulate intestinal flora? Introduction to common natural substances, probiotics and prebiotics
- 三十六计是什么
- 1个需求的一生,团队协作在云效钉钉小程序上可以这么玩
- test
- 针对NFT的网络钓鱼
猜你喜欢
Gut liver axis: host microbiota interaction affects hepatocarcinogenesis
STM32单片机ADC规则组多通道转换-DMA模式
Alibaba cloud IOT transfer to PostgreSQL database scheme
MYSQL50道基础练习题
【论文阅读】【3d目标检测】Improving 3D Object Detection with Channel-wise Transformer
Iron and intestinal flora
win10, mysql-8.0.26-winx64. Zip installation
zynq平台交叉编译器的安装
C语言: 指针的进阶
How to regulate intestinal flora? Introduction to common natural substances, probiotics and prebiotics
随机推荐
【时序】基于 TCN 的用于序列建模的通用卷积和循环网络的经验评估
Phishing for NFT
补:注解(Annotation)
单片机串口数据处理(1)——串口中断发送数据
Mysql---数据读写分离、多实例
Express middleware ① (use of Middleware)
第四章 --- 了解标准设备文件、过滤器和管道
Huawei machine test -- high precision integer addition
Cortex-M3寄存器组、汇编语言与C语言的接口介绍
STM32F4单片机ADC采样及ARM-DSP库的FFT
test
STM32 MCU ADC rule group multi-channel conversion DMA mode
记录一下盲注脚本
Express middleware ② (classification of Middleware)
Go反射—Go语言圣经学习笔记
Chlamydia infection -- causes, symptoms, treatment and Prevention
補:注解(Annotation)
MATLAB lit plusieurs diagrammes fig et les combine en un seul diagramme (sous forme de sous - Diagramme)
[echart] démarrer avec echart
Difference between LabVIEW small end sequence and large end sequence