| | |
circular link list
![]() |
•
•
Join Date: Aug 2004
Posts: 2
Reputation:
Solved Threads: 0
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.
If you don't consider the position of insertion, the answer becomes childish.
•
•
Join Date: Aug 2004
Posts: 4
Reputation:
Solved Threads: 0
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
then :
temp = last;
last->pointer = index;
last = index;
last -> pointer = temp->pointer;
and then have fun...
:surprised 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)
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)
:-(
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
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
![]() |
Similar Threads
- Single Linked Circular Link List (Java)
- how to check circular link list (C++)
- how to delete a node in a link list (C++)
- Circular linked list (C)
Other Threads in the C Forum
- Previous Thread: Help in Input output C files
- Next Thread: C programming question
| Thread Tools | Search this Thread |
* adobe api array arrays binarysearch calculate centimeter char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking hardware highest homework i/o ide inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h





