Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2006

Tip: Looking for answers? Try searching our database.

store or clone the Iterator

Thread view: 
p7371464@yahoo.com.tw - 04 Sep 2006 15:14 GMT
I have a LinkedList which stores some integer key.
For each key, I can use a computing function f() to get the
corresponding value.
In order to founding the key which has smallest value, I must work
through all key in the list.
Once found the key, I will remove the key from the list.
So I wrote the code as follow:

...
LinkedList<Integer> list = new LinkedList<Integer>();
...
...add some integer key to the list
....

ListIterator<Integer> it = list.listIterator();
ListIterator<Integer> it_save;
Integer min=Integer.MAX_VALUE;

//walk through all key in the list to found the key have minimum value
while(it.hasNext()){
   int key = it.next();
   int value = f(i);

   if(value < min){
       it.previous();
       It_save = it;
       it.next();
   }
}

//remove the key which has smallest value
it_save.remove();
....

But the above code can not work correctly, have any method to store the
ListIterator variable while
scan the list ?

Thanks in advance.
Oliver Wong - 07 Sep 2006 22:11 GMT
>I have a LinkedList which stores some integer key.
> For each key, I can use a computing function f() to get the
[quoted text clipped - 33 lines]
> ListIterator variable while
> scan the list ?

   If you can't change the data structure, you'll have to do 2 passes; once
to find the element of interest, and a second to remove that element.

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.