- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
什么是无界数组,无界数组和动态分配数组有什么区别?与无界数组相关的常见操作有哪些? (就像我们对堆栈数据结构有弹出和推送一样)
最佳答案
无界数组可以(并且通常是)静态分配。
实现无界数组时的主要关注点是提供类似动态数组的自由来在运行时决定数组大小,而不会因运行时内存分配而造成性能损失。
以下摘录自excellent article on unbounded arrays 简洁地解释了它 -
The general implementation strategy is as follows. We maintain an array of a fixed length
limit
and an internal indexsize
which tracks how many elements are actually in the array. When we add a new element we incrementsize
, when we remove an element we decrementsize
. The tricky issue is how to proceed when we are already at thelimit
and want to add another element. At that point, we allocate a new array with a largerlimit
and copy the elements we already have to the new array.
请注意,在运行时,直到 size
超过 limit
的初始值,无界数组不会涉及动态分配。
无界数组的一些功能(设计要求):
考虑到性能,与无界数组相关的唯一附加操作(与常规数组相比)是:
add_to_end()
delete_from_end()
允许修改无界数组的大小。
不提供像Insert_in_middle()
和Delete_in_middle()
这样的操作,请记住无界数组的主要设计原则,即性能。
有关更多详细信息,请查看此问题的答案 question .
注意:虽然问题特别提到动态分配的数组,但您可能还想查看 dynamic arrays 。动态数组的一个很好的例子是 C++ std::vector
它本身解决了一些与无界数组相同的设计原则。
关于arrays - 什么是无界数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21510201/
我有一个Foldable的Integer s 是无界的,因此我无法应用 Max折叠到它。 定义 Max 有意义吗? Nothing 的实例当一个值不存在时?有Ord a => Semigroup (M
我有两个简单的问题。我有一个 LinkedBlockingQueue,我将其简单地创建为 新的 LinkedBlockingQueue() 所以我认为这保证是无限的,对吗? 如果确实如此,那么说在此队
是否可以在未指定边界之一的情况下使用 git bisect。例如,如果我发现 HEAD 上有问题但我怀疑它在过去在某个时候有效,有没有办法告诉 git “尝试一次提交之前,如果那不起作用尝试两次提交之
我是一名优秀的程序员,十分优秀!