当前位置:网站首页>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"
边栏推荐
- 【FPGA教程案例49】控制案例1——基于FPGA的PID控制器verilog实现
- Events and scheduled tasks in Mysql
- 如何进行AI业务诊断,快速识别降本提效增长点?
- Snap - rotate the smallest number of an array
- MQ框架应用比较
- 洛谷P6586 蒟蒻火锅的盛宴
- Switch---Spanning Tree---Three-layer Architecture Summary
- 关于pom.xml文件
- findViewById返回null的问题
- JwsManager service interface implementation class - the jni implementation
猜你喜欢
随机推荐
send_sig: 内核执行流程
解决多线程调用sql存储过程问题
Selenium自动化测试框架工作原理你明白了吗?
map和set--天然的搜索和查找语义
洛谷P1196 银河英雄传说
简历里写了会代码,却依然过不了面试这一关
Embedded Sharing Collection 33
洛谷P4061 大吉大利,晚上吃鸡
交换机和路由器技术-29-OSPF虚链路
交换机和路由器技术-22/23-OSPF动态路由协议/链路状态同步过程
Bubble sort and heap sort
洛谷P2150 寿司晚宴
【yolov7系列三】实战从0构建训练自己的数据集
交换机和路由器技术-28-OSPF的NSSA区域
交换机和路由器技术-24-OSPF单区域配置
LeetCode814 Math Question Day 15 Binary Tree Series Value "814 Binary Tree Pruning"
FPGA工程师面试试题集锦121~130
【服务器安装mysql】centos7下使用mysql离线安装包安装mysql5.7
洛谷P2370 yyy2015c01 的 U 盘
每日一题-滑动窗口
![[Likou] 22. Bracket generation](/img/f6/435fe9e0b4c1545514d1bf195ffd44.png)







