← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 10503.c.2.b · 生成模型:未记录

向量尾部取值与中段移动

理解等级:中级

向量为了维持元素连续,中间 insert(i, x) 或 remove(i) 会让后续元素整体位移。在较长向量里,越靠前操作通常要移动越多元素。若只需要最近追加的元素,可以用 pop() 取出当时的末项,空向量会得到 None。尾部操作无需移动前面的元素。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《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