Hey everyone,

New to the forum and pretty new to Java! Yay! I am having a lot of trouble going about the move-to-front heuristic. I understand the concept, but cannot think of how to do it. I'm working in a LinkedSet, which is comprised of LinkedNodes of type T. I have an iterator for this and they all link to my SetADT. What I'm trying to do is work on the contains method. I want the method to look through the set and return true if the parameter is found, but also move commonly searched for parameters to the front of the list. I've thought about doing a loop through all them, then a loop through the contents to scan from the position of the target by index--...then setting the set index number - 1 to move the elements to the right and set the index 0 to the new parameter. However, I'm not sure I'm even on the right track to a solution like that. So here's some of my code (and ANY suggestions will be greatly appreciated):

Here are the variables:
private static Random rand = new Random();

private int count; // the current number of elements in the set

private LinearNode<T> contents;

Here's the method:
public boolean contains (T target)
{
// getElement returns the actual information
// contents will return part it is in the set


// Iterator<T> scan = this.iterator();
//
// while (scan.hasNext())
// {
// T compare = scan.next();
// if (compare.equals(target)){
// return true;
//
// }
// }
// return false;

for (int index = 0; index < count ; index++)
{
if (target == contents.getElement())
{
for ( ; index!=0 ; index--)
{
// contents[index] = contents[index - 1]; //move all of them to the right
// contents(0) = target;
}
}
}
return false;

}

So...any ideas? I'm pretty sure my code is crap.