C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 21st, 2003, 05:23 AM
ysd4477 ysd4477 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 1 ysd4477 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old May 21st, 2003, 08:34 AM
Analyser's Avatar
Analyser Analyser is offline
*bounce*
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Delft, The Netherlands
Posts: 513 Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 22 h 45 m 12 sec
Reputation Power: 41
Send a message via ICQ to Analyser
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/

Reply With Quote
  #3  
Old May 21st, 2003, 01:08 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 94
"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.

Reply With Quote
  #4  
Old May 21st, 2003, 01:52 PM
Analyser's Avatar
Analyser Analyser is offline
*bounce*
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Delft, The Netherlands
Posts: 513 Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 22 h 45 m 12 sec
Reputation Power: 41
Send a message via ICQ to Analyser
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.

Reply With Quote
  #5  
Old May 21st, 2003, 02:02 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,130 dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 19 h 43 m 21 sec
Reputation Power: 1949
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.

Reply With Quote
  #6  
Old May 21st, 2003, 04:54 PM
Analyser's Avatar
Analyser Analyser is offline
*bounce*
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Delft, The Netherlands
Posts: 513 Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 22 h 45 m 12 sec
Reputation Power: 41
Send a message via ICQ to Analyser
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

Reply With Quote
  #7  
Old May 21st, 2003, 06:10 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 94
yea i just figured out that wasnt possible... went to try it, and realized that you attach nodes on the fly

Reply With Quote
  #8  
Old May 22nd, 2003, 01:05 AM
walter76 walter76 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 18 walter76 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > linked list

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap