当前位置:网站首页>顺序表(下)
顺序表(下)
2022-08-08 04:24:00 【双一周学八天】
一、顺序表的删
头删:
void SLPopFront(SL* psl)
{
assert(psl);//遇到错误直接报错
int begin = 0;
while (begin < psl->size - 1)
{
psl->a[begin] == psl->a[begin + 1];
begin++;
}
}这种方法基本用不到,一般是采用尾删,头删没采用一次就要挪动n个数据,浪费资源。
尾删:
void SLPopBack(SL* psl)
{
assert(psl);
if (psl->size == 0)
return;
psl->size--;
}二、顺序表的插入
实质上是“增删查改”的增,之所以要弄头增头减是因为那两个经常会用到,单独列出来了。
void SLInsert(SL* psl, size_t pos, SLDataType x)
{
assert(psl);
assert(pos > psl->size);
SLCheckCapacity(psl);
size_t end=psl->size-1;
while (end > pos)
{
psl->a[end] = psl->a[end - 1];
end--;
}
psl->a[pos] = x;
psl->size++;
};这里破损用到的是size_t类型,这是一个无符号整数类型,在以后的库的学习中用的还是这个,因此我们现在就应该适应。
有一些要注意的点,不可 用下面的代码实现这一功能:
int end=psl->size;
while (end >= pos)
{
psl->a[end+1] = psl->a[end];
end--;
}这样当pos=0时会导致死循环,原因如下:
end被整型提升为无符号整数,当end为-1的时候在运算的时候会直接提取内存中的:
“11111111111111111111111111111111”一个极大的正数
三、顺序表的查
如下:
int SLFind(SL* psl, SLDataType x)
{
assert(psl);
for (int i = 0; i < psl->size; i++)
{
if (psl->a[i] == x)
{
return i;
}
}
return -1;
}四、顺序表的删
void SLErase(SL* psl, size_t pos)
{
assert(psl);
assert(pos > psl->size - 1);
size_t begin = pos + 1;
while (begin <= psl->size - 1)
{
psl -> a[begin - 1] = psl->a[begin];
begin++;
}
psl->size--;
}五、顺序表的改
void SLModify(SL* psl, size_t pos, SLDataType x)
{
assert(psl);
assert(pos < psl->size);
psl->a[pos] = x;
}
边栏推荐
- 包 package
- 牛客多校第6场赛后学习 B(两种做法)G(两种做法)M(两种写法)J
- y90.第六章 微服务、服务网格及Envoy实战 -- 服务网格基础(一)
- 【Review of Live Streaming】Synthesis MindSpore Usability SIG2022 First Half Review Summary
- NetCore uses Dapper to query data
- KMP和EXKMP(Z函数)
- leetcode: 322.零钱兑换
- The use of mmedicting get_flops. Py
- 【代码分析】图小样本异常检测方法:GDN:Few-shot Network Anomaly Detection via Cross-network Meta-learning
- 农产品直播带货持续升温,经济日报:冲流量勿忘质量
猜你喜欢

Machine Learning Notes: Learning Rate Warmup

unity之粒子特效制作图片拼合文字效果

The fledgling Xiao Li's 115th blog project notes on the creation of the domestic GD32F103RCT6 basic project

ES6解构赋值的使用说明

NetCore使用Dapper查询数据

Building a High-Performance Platform on AWS Using Presto and Alluxio to Support Real-Time Gaming Services

ToDesk企业版上新 | 十大新功能,让企业远控更安全、更便捷、更流畅

vulnhub-DC-5 target drone penetration record

10款自媒体人必备的免费工具,快速高效运营

包 package
随机推荐
L3-007 天梯地图(测试点2卡住了可以看下)
中国科学院金属研究所科研课题获华为技术认证,助力材料学发展新范式!
fail-fast 和 fail-safe 快速学习
32. 你知道Redis的字符串是怎么实现的吗?
2022/08/06 学习笔记 (day24) 集合
Bluetooth att gatt agreement
Awk syntax-03-awk expressions (if statements, while loops, for loops), execute shell commands in awk
一文带你彻底了解synchronized 和 Lock
Knowledge of DisplayPort-DP interface
Strong Net Cup 2019 - Casual Bet (Stacked Injection)
【保研面试】英文问题
The storage principle of NorFlash
[opencv] Introduction to opencv development kit
L3-006 Slash in the wind
Redis persistence mechanism, master-slave, sentry, cluster parsing cluster solution
高薪程序员&面试题精讲系列134之微服务网关有哪些限流算法?如何实现限流?
Heterogeneous on the Graph paper to share 】 【 small sample learning: HG - Meta: Graph Meta - learning over Heterogeneous Graphs
[Code Analysis] Graph small sample anomaly detection method: GDN: Few-shot Network Anomaly Detection via Cross-network Meta-learning
L3-005 垃圾箱分布
Week 4 Step by step building multi-layer neural network and application (1 & 2)