Linked list re-implementation in basic code. Very similar to the PureBasic linked list library, although there are some added features and benefits: * You can put linked lists inside structures (e.g. have linked lists inside linked lists) * You can have linked lists which have different types of elements in them * There are added procedures for working with lists in a more flexible way * Strings inside elements can be automatically freed when you delete elements * You can easily get the address of the base of the linked list and write generic list processing procedures There are three examples and some required files - you only really need to set the include path correctly and include the "double_linked_lists.pb" file. Feel free to use any way you like. It would be nice if you sent any enhancements back to me (dave@blitz-2000.co.uk). Here is some snippet info from the main source file. ; Background: ; The PureBasic linked lists are great things with only one real drawback - ; they cannot be used inside structures. And the documentation sucks. So I wrote ; these procedures to be as compatible as possible to the PB linkedlist library ; commands, to allow you to put lists into structures and so I could figure ; out the specifics of how the PB library commands worked so I could write ; some proper docs for them. ; ; First of all take a read of the LinkedList library documentation. To be able to use ; these functions you should know how pointers work and be sure that the PB commands ; do not satisfy your needs - they will save you a lot of hassle. ; ; OK, still here? Well, these commands are supposed to be very similar to the ; commands in the PB LinkedList library. You use them in pretty much the same ; way, but you should be aware of the following points: ; ; 0) The procedures are all named "dll_xxxxx()". The dll part stands for doubly ; linked list, not dynamic link library. Yes, I know that is what DLL normally stands ; for under Windows, but frankly I don't care. ; ; 1) You must use pointers to access the list items. Most commands will ; return a pointer to the list element. The lh_Current field of the ; list header structure will point to the start of the user's data for each ; element, or will have the value 8 for no item. This is the same operation ; as doing "@listname()". ; ; 2) When you create the list there is now an extra parameter which tells the ; function how big the user's data structure is. This will be used when ; allocating new elements for the list. You can set this to 0 if you like, but you ; must then always use the xxxxxSize() procedures to create new elements. ; ; 3) There is now a procedure dll_DeleteList() which should be called when ; you no longer need to use the list. ; ; 4) There is no guarantee that these procedures mimic the PureBasic ones exactly. ; ; 5) Check out the examples for, well, err, examples of using these procedures. ; ; 6) You can get these procedures to automatically free string memory when you clear ; a list or delete an element. To be able to do this, you should be using a single ; type/size of element in the linked list (as you would with normal PB lists) ; and pass the address of a variable with the same structure to teh dll_NewList() ; procedure. This variable should be set up so that all fields you do not want ; automatically freed (i.e. all fields which are not strings) are set to -1. ; Passing NULL instead of an address means the automatic string freeing code will ; not be called. ; ; 666) These procedures are not thread safe! ; History: ; 6th February 2008 Updates for PB 4.x by "Dare" ; 25th January 2005 Changed dll_DeleteElement() to always go backwards in the list ; Added dll_DeleteElementOld() for the old behaviour (you cannot have variable parameters in procedures yet) ; Added dll_SwapElements() ; 3rd November 2004 Changes to be compatible to PB 3.92 linked list library ; Optimised dll_ListIndex() (although still not tested) - dll_CountList() was already done ;p ; 5th July 2004 Added procedures for inserting (introduce) and removing already existing elements to and from lists ; Added explanations for all procedures ; 4th July 2004 Added ability to automatically free strings if the list contains a single type of node ; Updated to use PureBasic's memory functions ; All procedures are declared in one section at the top of the source now ; 27th June 2003 Fixed the DeleteElement procedure so that it really is like the PureBasic command ; 11th June 2003 Changed the memory allocation calls (was heap) as it was possible to run out of memory easily ; 8th December 2002 Fixed stupid bugs in dll_NextElement and dll_PreviousElement. Was treating the current element pointer as a listnode sructure, when it should have subtracted the size of the listnode structure first ; Changed dll_PreviousElement to work more like the PB command - should not move to tail of list if there is no current element ; 2nd December 2002 Implemented the list index tracking inside the list header (obviously will get messed up if the user changes the current item pointer or the index itself) ; Added dll_SelectElement() ; Fixed the add and insert procedures as they would not have worked ; Added dll_ClearList(), dll_FirstElement(), dll_LastElement(), dll_NextElement(), dll_PrevElement(), dll_ResetList(), dll_InsertElement(), dll_InsertElementSize() ; 1st December 2002 Added dll_NewList(), dll_DeleteList(), dll_ChangeCurrentElement(), dll_AddElement(), dll_AddElementSize(), dll_DeleteElement() ; 30th November 2002 Created