gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Linked List code

#167678 - spencer723 - Sun Mar 22, 2009 3:17 am

Hey everyone, I've made a singly linked list creation and manipulation "library" so to speak. I've run this code on the GBA with no problems. It stores integers but can be altered to store almost anything. If you do change the type it can hold you will need to change the references in functions and the entire searchList() function, but that's pretty much it.

You can download the source here: http://scs.carleton.ca/~selliot3/linked_list_GBA.rar

If you can't download like that, visit this page and click on the link: http://scs.carleton.ca/~selliot3/

EDIT: This code should also work fine on the DS. I haven't tested it because my DS compiler just doesn't seem to want to compile anything at all.

#167681 - Miked0801 - Sun Mar 22, 2009 5:13 am

stl::slist

#167732 - elyk1212 - Tue Mar 24, 2009 1:23 am

Code:

but can be altered to store almost anything.


To avoid having to modify code when using a different type... you could change to C++ and use templates.

I understand there is danger to code being duplicated in the binary for some compilers, but there are ways to avoid this too (typedef LinkedList<int> LinkedListInt ?).


But yeah, as Mike alluded to, these things are already around in C++ for your consumption in STL, etc. But that doesn't mean you shouldn't try to customize or roll your own for your/others use... if it makes sense.


BTW, I recently tested.. and STL does work for GBA... at least trivially. I haven't used it enough to say if there is a hit or caveat, in GBA anyhow.