C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Query related to link list

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language
View previous topic :: View next topic  
Author Message
deba
Guest





PostPosted: Thu May 17, 2007 9:11 am    Post subject: Query related to link list Reply with quote



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
Back to top
Tejas Kokje
Guest





PostPosted: Thu May 17, 2007 9:11 am    Post subject: Re: Query related to link list Reply with quote



deba wrote:

Quote:
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

Here is the pseudocode

int node_delete(node_t **node) {

if (!node || !*node)
return -1;

//if I am last node, then free and set myself to NULL.
if (*node->next == NULL) {
free(*node);
*node = NULL;
}
else {
//if there is a node after me, copy its contents to me and free that next
//node

*node->data = *node->next->data;
*node->next = *node->next->next;
free(*node->next);
}

return 0;
}

Hope this helps.

Tejas Kokje
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.