mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-28 04:42:48 +08:00
deploy
This commit is contained in:
@ -3450,7 +3450,7 @@
|
||||
<div class="admonition question">
|
||||
<p class="admonition-title">在 Python 中初始化 <code>n = [1, 2, 3]</code> 后,这 3 个元素的地址是相连的,但是初始化 <code>m = [2, 1, 3]</code> 会发现它们每个元素的 id 并不是连续的,而是分别跟 <code>n</code> 中的相同。这些元素地址不连续,那么 <code>m</code> 还是数组吗?</p>
|
||||
<p>假如把列表元素换成链表节点 <code>n = [n1, n2, n3, n4, n5]</code> ,通常情况下这五个节点对象也是被分散存储在内存各处的。然而,给定一个列表索引,我们仍然可以在 <span class="arithmatex">\(O(1)\)</span> 时间内获取到节点内存地址,从而访问到对应的节点。这是因为数组中存储的是节点的引用,而非节点本身。</p>
|
||||
<p>与许多语言不同的是,在 Python 中数字也被包装为对象,列表中存储的不是数字本身,而是对数字的引用。因此,我们会发现两个数组中的相同数字拥有同一个 id ,并且这些数字的内存地址是无需连续的。</p>
|
||||
<p>与许多语言不同的是,在 Python 中数字也被包装为对象,列表中存储的不是数字本身,而是对数字的引用。因此,我们会发现两个数组中的相同数字拥有同一个 id ,并且这些数字的内存地址是无须连续的。</p>
|
||||
</div>
|
||||
<div class="admonition question">
|
||||
<p class="admonition-title">C++ STL 里面的 std::list 已经实现了双向链表,但好像一些算法的书上都不怎么直接用这个,是不是有什么局限性呢?</p>
|
||||
|
Reference in New Issue
Block a user