The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
linked list
Discuss linked list in the C Programming forum on Dev Shed. linked list C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 21st, 2003, 05:23 AM
|
|
Junior Member
|
|
Join Date: May 2003
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
linked list
how can i delete a node in a single link list, if i know the address of that node(only) i.e to be deleted and i dont know the address of root node.
how can i find in a double linked list, if the pointer is missing.means, the pointer is not pointing to the next node and it may point to some other double linked list also.so i have to find out which node's pointer is missing
|

May 21st, 2003, 08:34 AM
|
 |
*bounce*
|
|
Join Date: Jan 2002
Location: Delft, The Netherlands
|
|
Quote: | how can i delete a node in a single link list, if i know the address of that node(only) i.e to be deleted and i dont know the address of root node. |
You can't. You need both addresses; the address of the node to delete, and the address of any of the preceding nodes. There's no other way, period.
Quote: | how can i find in a double linked list, if the pointer is missing.means, the pointer is not pointing to the next node and it may point to some other double linked list also.so i have to find out which node's pointer is missing |
Pointers are never "missing". They either contain an address, or they are NULL. That means, if you're looking at a pointer's value, you can't tell if which linked list it points to. To put it simple: the only thing you can determine from a pointer's value is if it's pointing somewhere, or not (NULL). It does not convey any type information at all.
Sorry 
__________________
"A poor programmer is he who blames his tools."
http://analyser.oli.tudelft.nl/
|

May 21st, 2003, 01:08 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
|
"how can i delete a node in a single link list, if i know the address of that node(only) i.e to be deleted and i dont know the address of root node."
- i was thinking of maybe a hack way to do it. if u can determine the size of the node, then u know how many bytes in memory it occupies. and i believe nodes in a list are all stored sequentially in memory, so u could offset the pointer to the node to get pointers to the nodes in front/back of it.
|

May 21st, 2003, 01:52 PM
|
 |
*bounce*
|
|
Join Date: Jan 2002
Location: Delft, The Netherlands
|
|
Quote: | ...I believe nodes in a list are all stored sequentially in memory... |
No. You're thinking of elements in an array. With linked lists the following scenario is possible: - allocate memory for a node and add it to the list
- allocate more memory from the heap for other data structures
- allocate another node and add it to the list
In the above scenario, the chance of the two nodes being adjecent in memory is well-nigh nil.
|

May 21st, 2003, 02:02 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
Stupid question:
How could any functioning program find itself in the situation of not knowing the address of the root node of a linked list that it had created?
I don't understand how the situation ysd4477 is trying to solve could ever arise unless the program has a bug in it. In that case, the solution is to correct the code and recompile.
|

May 21st, 2003, 04:54 PM
|
 |
*bounce*
|
|
Join Date: Jan 2002
Location: Delft, The Netherlands
|
|
Quote: I don't understand how the situation ysd4477 is trying to solve could ever arise unless the program has a bug in it. |
It's not a stupid question; it's a valid point
Code:
void add_node_to_list (Node *ptr) {
???
}
That's an example of ysd4477's description, and yes, it's either an implementation or design flaw.
Quote: | In that case, the solution is to correct the code and recompile. |
Sounds like sound advice to me 
|

May 21st, 2003, 06:10 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
|
yea i just figured out that wasnt possible... went to try it, and realized that you attach nodes on the fly
|

May 22nd, 2003, 01:05 AM
|
|
Junior Member
|
|
Join Date: May 2003
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Quote: | how can i delete a node in a single link list, if i know the address of that node(only) i.e to be deleted and i dont know the address of root node. |
If the last item of your single linked list is not NULL (which is the standard way) but points to the first item of the linked list, there is a way in calculating the pointer to the item before the item to be deleted. Then you have a chance.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|