Moving a stack of size 3, again, if I want to go over there, I need to make sure I can put the spare one over here before I move the bottom one, I can't cover up any of the smaller ones with the larger one, but I can get it there.
移动上面的三个圆盘的话,我在移动最底下的圆盘之前,同样要确保剩下的,是在另外一个柱子上,因为我不能把大的圆盘,放在小的上面。
OK, that's not so bad. Moving a stack of size 2 if I want to go there, I need to put this one temporarily over here so I can move the bottom one before I move it over.
好,并不那么难,移动上面两个圆盘的话2,我需要把最小的盘子,临时先放到多余的柱子上来,这样才能在把它移过来之前,把最底下的盘子放到目标柱子上。
I intentionally used this very common analogy of a stack of trays in a cafeteria.
我故意使用这个普遍的类比,就像,自助餐厅的一堆托盘。
There should be the rest of a stack over here.
那里还有几叠。
If I want to move this stack here, I'm going to take a stack of size n minus 1 move it to the spare spot, now I can move the base disk over, and then I'm going to move that stack of size n minus 1 to there. That's literally what I did, OK?
如果我想移动这些圆盘,我先把从n-1个圆盘1,移动到多余的柱子上去,这样我就能把最底下的圆盘放到这儿了,然后再把从n-1个圆盘放到这儿来,这就是确切的我怎么做的对不对?
Well, if you want to call a function, it's like putting another tray on that stack of trays and that tray represents a chunk of memory that, that function can use.
嗯,如果你想调用一个函数,这就像把一个托盘放到另一个托盘上,托盘代表一块,函数可以使用的内存。
So, certainly the CS50 Library designed to be dynamic and, in fact, any time you call get string, we are, in fact, ; allocating a chunk of RAM but it's not coming from the stack; it's actually coming from this portion of memory called the heap.
所以,Cs50库是动态设计的,实际上,每次你调用GetSting时,我们分配一块内存,但它不是来自栈;,而是来自于叫做堆的,内存的一部分。
应用推荐