Results 1 to 3 of 3
- 05-08-2011, 03:17 AM #1
Member
- Join Date
- May 2011
- Posts
- 1
- Rep Power
- 0
Linked List: Removing Largest Element Using Iterator
how can I remove the largest element from a linkedlist in java? I know I can use get() or remove() functions to retrieve / remove the elements. But I want to make it efficient. I want to use iterator. Do you have any idea how i can do it? Note that I dont want to create my own linkedlist. I dont even want to sort my linkedlist.
Can I do a linear search for this? If so, how can I keep track of the pointer (or iterator) that points to the largest element. Any help will be appreciated.
- 05-08-2011, 04:43 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
First, you haven't defined what you mean by 'largest element'. I presume you mean largest based upon some sort of Comparator or Comparable. Second, a simple implementation would be to loop over the list and search based upon your criteria - removing the appropriate element when complete.
Why? Efficiency is relative, and searching a List is quite simple and quite effective. Without any context why you want to speed something up and what you're doing advice is all relative, you could use any number of methods - trees, Lists, etc...each of which has their place and may be more efficient in one context, less so in another (relative to other methods)But I want to make it efficient. I want to use iterator.
- 05-08-2011, 05:28 AM #3
Senior Member
- Join Date
- Feb 2011
- Location
- Georgia, USA
- Posts
- 122
- Rep Power
- 0
Similar Threads
-
linked list iterator
By TopNFalvors in forum New To JavaReplies: 3Last Post: 03-31-2011, 03:03 AM -
How to access an element of a linked list inside another linked list?
By smtwtfs in forum New To JavaReplies: 4Last Post: 02-21-2011, 09:34 AM -
need help with removing repetitions from linked list...
By OptimusPrime in forum New To JavaReplies: 8Last Post: 03-09-2010, 08:29 PM -
Convert Linked List Object element to String
By CirKuT in forum New To JavaReplies: 2Last Post: 12-13-2008, 05:22 AM -
Creating an Iterator for Linked List
By spanky in forum New To JavaReplies: 3Last Post: 10-05-2008, 07:16 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks