I added
generic k-ary tree data structure with simple traversal method (breadth first and depth first) using callback a couple of months ago. Probably you could make a good use of it (or better, improve with more traversal methods or whatever that can be done in general with a tree data structure).
P.S.: Despite the name, actually you can use the data structure as graph, just don't use the two traversal methods above as they don't checked visited nodes so it may cause garden path problem or leads to application crash.