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.
Printable View
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.
a doubly linked list looks like this.....
by this i mean that root has a pointer to null and a pointer to node1Code:NULL <--root(node0) <----> node1<---->node2<---->node3---->NULL
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.
If we wanted to add a new node lets call it node4 back where node1 used to be....Code:NULL <--root<---->node2<---->node3---->NULL
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
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.
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.