Can we calculate the address of previous element in a link list if we have the address of the current element? Can somebody suggest any method how to implement this? the only hint i have is that link elements are allocated memory from a heap.
Can we calculate the address of previous element in a link list if we have the address of the current element? Can somebody suggest any method how to implement this? the only hint i have is that link elements are allocated memory from a heap.
Hi,
If it is doubly linked list you can find the previous node address very easily like currnetNode.left().
If it is single linked list Again you have to check from the root node.for that you have to write a loop like this.
node=root;
cnode=currentnode;
while(node.next()!=cnode){
previousnode=node;
}
Thanks
--Suresh--
i know this can b done this way..
but wat i was looking for is dat if i know the address of a block allocated thru(malloc or calloc or new)..is it possible to know the address of next block to b allocated...
but i recently came to know dis is not possible in ne way
neways thanks for the concern