当前位置:网站首页>Optimization is a kind of habit low starting point is the "standing near the critical"
Optimization is a kind of habit low starting point is the "standing near the critical"
2022-08-11 04:52:00 【a music】
1. Example: dynamic insertion and deletion of arrays
Consider the critical value
This critical value, not necessarily the last element

- Delete an element:

The first method: when the maximum value is obtained: i=size-1, the expression is: elements[size-2]=elements[size-1]
Second approach: When the maximum value is obtained: i=size-1, the expression is: elements[size-1]=elements[size] This is obviously not in line with the design. For example, the current array has size elements, thenThe last element should be elements[size-1]
In fact, crossing the boundary is also a thinking angle. If you stand at the covered angle, then the last covered element in the critical is the penultimate element of the current array elements[size-2]
The second approach: The loop judgment condition should be modified to be correct: for(int i = index; i < size-1; i++)
The first approach: is to stand at the cover angle, and also stand close to the 'threshold' (closer to the last element)The angle of font>, not easy to make mistakes, recommended
- Add an element:

In adding elements here: There is no problem with practice 1 and practice 2, but it is recommended,
Uniform Habits: The starting point is to "stand near critical"
边栏推荐
- 【人话版】WEB3将至之“权益的游戏”
- ERROR: Could not install packages due to an OSError: [Errno 2] 没有那个文件或目录: ‘/data/xxxx
- ALSA音频架构
- Mysql: set the primary key to automatically increase the starting value
- Research on a Consensus Mechanism-Based Anti-Runaway Scheme for Digital Trunking Terminals
- ALSA音频架构 -- aplay播放流程分析
- 交换机和路由器技术-32-命名ACL
- Redis: Solve the problem of modifying the same key with distributed high concurrency
- Apache初体验
- CAD2020 打开错误报告 e06d7363h Exception at 13644F69h
猜你喜欢

IP-Guard如何禁止运行U盘程序

简历里写了会代码,却依然过不了面试这一关

"239 Sliding Window Maximum Value" on the 16th day of LeetCode brushing

CAD2020 打开错误报告 e06d7363h Exception at 13644F69h

嵌入式分享合集33

zabbix构建企业级监控告警平台

Harvesting of radio frequency energy

JVM 垃圾回收的概述与机制

Embedded Sharing Collection 33

Object Creation and Display Transformation
随机推荐
JVM 垃圾回收的概述与机制
ALSA音频架构
标识密码技术在 IMS 网络中的应用
Redis deletes keys in batches according to regular rules
findViewById返回null的问题
[Likou] 22. Bracket generation
优化是一种习惯●出发点是“站在靠近临界“的地方
无线电射频能量的收集
Clang Code Model: Error: The clangbackend executable “X:/clangbackend.exe“ could not be started
c语言fprintf、fscanf、sscanf以及sprintf函数知识要点总结
Research on a Consensus Mechanism-Based Anti-Runaway Scheme for Digital Trunking Terminals
paddlepaddle实现CS_CE Loss且并入PaddleClas
监听U盘插入 拔出 消息,获得U盘盘符
在 关闭页面/卸载(unload)文档 之前向服务器发送请求
洛谷P4032 火锅盛宴
ALSA音频架构 -- snd_pcm_open函数分析
The shortest path out of the maze
如何进行AI业务诊断,快速识别降本提效增长点?
对象的创建以及显示转换
交换机和路由器技术-36-端口镜像