知识卡片
向量尾部取值与中段移动
向量为了维持元素连续,中间 insert(i, x) 或 remove(i) 会让后续元素整体位移。在较长向量里,越靠前操作通常要移动越多元素。若只需要最近追加的元素,可以用 pop() 取出当时的末项,空向量会得到 None。尾部操作无需移动前面的元素。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Fundamental Types 动态向量的构造、容量与更新 · 查看原书依据
elements wherever you like in a vector, although these operations shift all the elements after the affected position forward or backward, so they may be
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|动态向量的构造、容量与更新,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#vectors`
- 结论依据:原文直接给出插入、移除触发后续位移的原因,再用重复 pop 展示末尾取值和空状态。
- 原始内容:elements wherever you like in a vector, although these operations shift all the elements after the affected position forward or backward, so they may be