Groovy hepcat Barry Schwarz <sc******@doezl.netwas jivin' on Thu, 17 May
2007 05:19:05 -0700. It's a cool scene! Dig it.
On 16 May 2007 22:18:15 -0700, deba <de**************@gmail.comwrote:
>>Hi
i want to know is it possible to delete the node where my
pointer currently pointing without knowing the head node address.Dis
question ask to me in an interview.
I really want to know the soloution of it.Thanx
If the node you currently point to is not last, then you can copy the next
node into your node (and delete that one). This has the logical effect of
deleting the node you are pointing to but not the physical effect (you
freed a different block of memory).
If you are pointing to the last node of the list, you must somehow have
access to the next-to-last node so you can reset its "next" pointer.
Of course, it's different (simpler) for double linked lists. Since the
current node has pointers not only to the next node but also the previous
one, you simply set the next node's "previous" pointer to point at the
previous node (or set it to NULL, adjusting the "head" pointer to point at
the next node, if there is no previous node), set the previous node's
"next" pointer to point at the next node (or set it to NULL, adjusting the
"tail" pointer to point at the previous node, if there is no next node),
then remove the current node by setting its "next" and "previous" pointers
to NULL.
--
Dig the sig!
----------- Peter 'Shaggy' Haywood ------------
Ain't I'm a dawg!!