gregulator
Senior member
Okay so I am programming in java and am making a set class that does not need to be sorted but the user needs to be able to insert integers, see if an integer is present, intersec and union the sets. I am wondering if there is a better way to do some of the operations I need to do, because right now, my code is kind of messy and inefficient. I can only use a linear link, no trees or double links or anything. I would like to know if there is a better way to search for an integer in the list rather than going through the list link by link and checking the data stored in each node. The way I have the class set up is that set is one object, and nodes are another so that the set object can point to the "head" of a bunch of linked nodes. This becomes a big problem when intersecting sets because if i have sets A and B, for each node in A, i have to go through the entire list of nodes in B, comparing the data. Thanks for any help, I am just trying to think of a better way to do this but i might just have to use some other data structure.