The word doc seems decently helpful, though slightly misguided. Here's how I would approach the problem:
1) Make a class that implements the SelfOrgList interface.
Code:
public class MoveToFrontSO implements SelfOrgList {
Node listHead;
public void clear() {
// clean out the list, (set listHead to null)
}
public int search(String word) {
/*
Here you will need to keep two references, one to the current node that you
are inspecting and one to the last node that you inspected (just make a special case for the first node). If what you are currently inspecting is the word, then
1) set the next of the previous to the next of the current
2) set the next of the current to listHead
3) set listHead = current;
return the number of inspections. If you reach the end of the list, multiply the number of inspections by -1 and return it.
*/
}
public void insert(String word) {
/*
Make a new node with this word as the string and the next equal to the front of the list. Set listHead = the new node.
}
}
Hopefully this will get you started. The other algorithm is a little bit different, but shouldn't be too bad. If you have any more questions, just post them.
Hope this helps.
Bookmarks