modifying balaji's approach and adding few more things:
traverse until u find the node...then
loop
copy data from the next node
until u reach the last node
then delete the last node.
Ex:
Consider the SLL:
1 -> 2 -> 3 -> 4 -> 5
Suppose the head pointer is lost and is currently pointing to '2'.
1) if u want to delete 3:
the scenario is like this:
1 -> 2 -> 3 -> 4 -> 5
|
lost_head_ptr
declare another ptr pointing to the location of lost_head_ptr....traverse
until u find 3...
1 ------> 2 ----------> 3 ---------> 4 -> 5
| |
lost_head_ptr temp_iter
then apply the algorithm...
1 -> 2 -> 4 -> 4 -> 5
|
temp_iter
1 -> 2 -> 4 -> 5 -> 5
|
temp_iter
1 -> 2 -> 4 -> 5
2) If u want to delete 1: there exists no way(since its SLL and header is
lost)..unless u can find out the location of the byte pointing to 2(this can
be done btw...little complex though)...but for now we assume we can't delete
1.
1 -> 2 -> 4 -> 4 -> 5
*
On Sun, Mar 13, 2011 at 10:27 PM, abhijith reddy
<[email protected]>wrote:
> copy data from the next node and then delete that next node.
>
> Say you need to delete 3
>
> 1 -> 2 -> 3 -> 4 -> 5
>
> 1 -> 2 -> 4 -> 4 -> 5
> *
> Now delete node which is next to '*'.
>
>
> On Sun, Mar 13, 2011 at 10:23 PM, UMESH KUMAR <[email protected]>wrote:
>
>> hi
>>
>> Given a singly Link list but Head of the List is
>> unknown so my question is that ................
>>
>> How to delete a given node from the List???????????
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.