C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-28-2001, 07:53 PM   #1
Registered User
 
Join Date: Nov 2001
Posts: 1
Unhappy double linked lists

i am having difficulty writting a function that adds and deletes a node from a double linked list. could someone please help me out.
i am making use of pointers.
susyb is offline   Reply With Quote
Old 11-28-2001, 10:29 PM   #2
Skunkmeister
 
Stoned_Coder's Avatar
 
Join Date: Aug 2001
Posts: 2,572
a doubly linked list looks like this.....
Code:
NULL <--root(node0) <----> node1<---->node2<---->node3---->NULL
by this i mean that root has a pointer to null and a pointer to node1
node1 has a pointer to node 2 but also has a pointer to root.

if we wanted to delete node1....

node2 pointer to node 1 would have to point to root
root pointer to node1 would be altered to point to node2
Dont forget to free memory associated with node1. You now have this sort of structure.
Code:
NULL <--root<---->node2<---->node3---->NULL
If we wanted to add a new node lets call it node4 back where node1 used to be....

root pointer to node2 altered to point to node4
node4 pointer(prev.) set to root
node4 pointer(next) set to node2
node2 pointer to root altered to point to node4.

ending up with....
Code:
NULL <--root <----> node4<---->node2<---->node3---->NULL
__________________
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Stoned_Coder is offline   Reply With Quote
Old 11-29-2001, 04:44 AM   #3
Unregistered
Guest
 
Posts: n/a
Thumbs up Interesting

Pretty good explanaition of linked lists there.

But do you (or anyone else) know of any GOOD tut's or books that deal with linked lists. I've read a couple of them including the short one on this site and understand the logic behind deleting and adding nodes but would like to see a few examples of how different people implement this in code.

Im about to write a small prog for storing records in a binary file for my class.
  Reply With Quote
Old 11-29-2001, 06:09 AM   #4
Skunkmeister
 
Stoned_Coder's Avatar
 
Join Date: Aug 2001
Posts: 2,572
do a search at google for linked lists. search for a c implementation to see the code properly. In c++ linked lists are normally done a little different by using the stl.
__________________
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Stoned_Coder is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Double pointers and linked lists. simo_r C Programming 2 05-06-2008 04:25 AM
Singly Linked Lists: Clarification Needed jedispy C++ Programming 4 12-14-2006 05:30 PM
need some help with last part of arrays Lince C Programming 3 11-18-2006 09:13 AM
Double linked lists and a structure to hold them plus a name. Nit C Programming 1 03-21-2002 06:10 PM
doubly linked lists qwertiop C++ Programming 3 10-03-2001 06:25 PM


All times are GMT -6. The time now is 05:46 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22