Here's the problem with that technique, and by the way, a number of programming languages use this, including Lisp.
这会指向元素的值,然后对内存进行切分,关于这种技术有个问题,顺路说下。
I'm walking along the list once, taking two things and saying, make sure the biggest one is next.
我遍历一次列表,每次取两个值,确认最大的元素在后面一个。
Which may take up some arbitrary amount of memory. In that case, I'm back to this problem.
然后将接下来的每一个内存块设置为,指向数组对应元素值的指针。
The better way to think about this is, suppose, rather than starting at the beginning, I just grabbed some spot at random, like this one.
不从数组的头开始遍历,我随即的从数组中抓一个元素,比如这个,我去看看这个元素的值。
First line says, 0 if i is 0, that means I'm looking at the very last element.
第一行的意思是,如果i的值是,就意味着我看到的,是最后一个元素。
Now I look at that element. Is it the thing I'm looking for? If I'm really lucky, it is. If not, I look at the value of that point here and the thing I'm looking for. And for sake of argument let's assume that the thing I'm looking for is smaller than the value here.
现在我们瞧瞧指向的元素,它是我们找的值么?如果足够幸运,他就是,如果不是,我们比较指向的元素,同我们要找的元素,方便起见,假设要找的元素比这里的值要小。
If not, what could I do?
好,我可以先看看这个元素的值?
You can also assign to a list, or to an element of a list. So ivy sub 1, f -15 or example, could be assigned minus 15, and that will actually mutate the list.
此外你还可以给一个数组,或者数组内部的元素赋值,比如ivy。sub,可以被赋值为,这确实改变了数组。
To get any location in memory, to get to any value of the list, I simply have to say which element do I want to get, I know that these things are stored in a particular size multiply that index by 4, add it to start, and then it's in a constant amount of time I can go to that location and get out the cell.
取得列表中的任何一个值,简单说来,想要取得列表中的任何元素,我知道这些元素存在特定的大小中,把下标乘以4,加到start上,然后定位到内存单元,并取出值就是固定的时间了,好的,如果元素以固定大小存储。
应用推荐