Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-08-2008, 03:18 AM
Member
 
Join Date: Feb 2008
Posts: 1
MaliceN is on a distinguished road
LinkedLists and Move to Front heuristic
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Move to forum 'New To Java' jvasilj1 New To Java 2 02-02-2008 10:22 AM
Move to forum 'New To Java' lalithalydia New To Java 1 01-31-2008 09:16 AM
Move to correct forum JavaJunkie1983 Introductions 7 01-23-2008 05:04 AM
Move to correct forum... Winarto Introductions 3 01-18-2008 05:00 AM
Help with Move Shape romina AWT / Swing 1 08-07-2007 07:27 AM


All times are GMT +3. The time now is 08:11 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org