But we already know the last block in the chain. It's memory location is saved in pChain->tail, no?neuraleskimo wrote:Because I see you are online, here is a quick answer to this.PsySc0rpi0n wrote:Bur when I try to do the same when the list is not empty, I think I don't understand the following line:Code: Select all
pChain->tail->next = newBlock;
We need to find the last block in the chain and then update its next pointer to point to the new node (or block). That is all the code does, I just wrote it in a terse form. A more verbose form is:We are about to start dinner. Will think about the rest and reply later...Code: Select all
node* old_last_node = pChain->tail; old_last_node->next = newBlock;
(I think I'm already mixing names. I started with myChain and now I'm calling it pChain)
Enjoy dinner. I'm not sure I'll still around. It's 1:10 am here.
PS:
And another thing I want to ask is about free(). When the program exits, where do we have to place the free(newBlock); line of code?