Data structure of the program was a linked list of linked list.  It functions exactly like a graph.