circular link list

Reply

Join Date: Aug 2004
Posts: 13
Reputation: apurva agarwal is an unknown quantity at this point 
Solved Threads: 0
apurva agarwal apurva agarwal is offline Offline
Newbie Poster

circular link list

 
2
  #1
Aug 30th, 2004
insert a node in circular link list without traversing it.

you have to insert the node at any place "without traversing it

help me out!!! in this
TO RISE TO GREAT HEIGHT ONE MUST GO TO GREAT DEPTH
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 2
Reputation: ganesh is an unknown quantity at this point 
Solved Threads: 0
ganesh ganesh is offline Offline
Newbie Poster

Re: circular link list

 
2
  #2
Aug 30th, 2004
If you want to insert a node a node at a particular position, You must know the key value or the distance from head (or) tail. In both the cases you have to traverse the list. If the memory is not dynamic then, you can just add the distance*sizeofnode to the head and insert the node there.

If you don't consider the position of insertion, the answer becomes childish.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 4
Reputation: wild_potatos is an unknown quantity at this point 
Solved Threads: 0
wild_potatos wild_potatos is offline Offline
Newbie Poster

Re: circular link list

 
2
  #3
Aug 30th, 2004
you can do it as follows, use a pointer to point to the last node " consider the list as a queue " of the list consider it's name is ((( last ))) and the node you want to add is ((( index ))) and define another pointer ((( temp )))

then :

temp = last;
last->pointer = index;
last = index;
last -> pointer = temp->pointer;

and then have fun... :surprised
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 11
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: circular link list

 
1
  #4
Aug 30th, 2004
Huh? It sounds like the assignment is, given a node in the target list, insert a new node into it. Otherwise you'd have an assignment like "insert in sorted order"

So, given a target node called 'target' and you want to insert 'toBeInserted' you generally need to:

A) Remove the toBeInserted node from whatever list its on
B) Add it to the new list before or after 'target', whichever is appropriate.

And the general steps for removal are (with the current node bing 'this'):

set prior's next to this next
set next's prior to be this' prior
set this' next to this
set this' prior to prior

and to insert before target you do something like this:

this' next is target
this' prior is target's prior
target's prior is this
this' prior's next is this

(to insert after is similar, but slightly different of course)

Hope that helps!

(note to moderator's: trying not to do the assignment, but to explain it. Walks a fine line, there)
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 11
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: circular link list

 
0
  #5
Aug 30th, 2004
Oops! Bug! The last line in 'general steps for removal are' should read:
set this' prior to this (not to prior)
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 13
Reputation: apurva agarwal is an unknown quantity at this point 
Solved Threads: 0
apurva agarwal apurva agarwal is offline Offline
Newbie Poster

Re: circular link list

 
0
  #6
Aug 30th, 2004
well explain it in amore simple manner i could not reall yget the whole of it
TO RISE TO GREAT HEIGHT ONE MUST GO TO GREAT DEPTH
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 11
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: circular link list

 
0
  #7
Aug 30th, 2004
:-(

I guess I should stop answering questions with anything but Google answers. Here's what Google suggests for "circular linked list insertion algorithm":

http://www.greatsnakes.com/savannah/clist.asp
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC