I currently am writing a Java program that matches users to recommended student groups based on their answers to questions regarding special interests, major, etc. Each user is defined by a User object. Each student group is defined by a Group object.
I have a working method of assigning each specific Group instance a particular score- for example, the Group schoolNewspaper has a score of 72, and the group filmMakers has a score of 99.
Each Group object also has an integer value, called
int difference;
This represents the similarities by absolute value between the user's score and the score of the clubs. For example, if someone takes the quiz and gets 71, the difference value for the schoolNewspaper is assigned to 1, and the filmMakers Group is assigned a difference value of 26.
The user's score is compared to all of the Group scores, thereby assigning each Group a difference value. I would like to form a linked list containing all of the Groups, then order it such that those with the smallest difference value are at the head of the list. This is because I will be using the 5 most similar Groups to create a recommendation for the user, and I feel it would be more effective to sort the list and take the first 5 elements rather than searching repeatedly.
I am not sure if a current sort method exists in the Java libraries that might make this process easier- as sometimes I try to reinvent the wheel without realizing how certain library operations can be used. So, is there a particular way of using an integer value defined within a unique object to order a linked list of such objects? I'm relatively new to programming, so any help in terms of approach/theory would be greatly appreciated.
Edit: Perhaps another data structure may be better for this sorting rather than a linked list?