Results 1 to 3 of 3
- 05-02-2009, 02:46 AM #1
Member
- Join Date
- Jan 2009
- Posts
- 9
- Rep Power
- 0
Having trouble removing from TreeSet
Take a look. The remove operation never returns TRUE. What am I doing wrong?
Java Code:public static double closestPoints (Point [] xQueue) { Point closestLeft, closestRight, current, check,tmp; int c,n,t; double delta, newDelta; yComparator yC = new yComparator(); // initX ************************** Arrays.sort(xQueue); // sort xQueue by X-coordinate // initY ************************** TreeSet<Point> yTree = new TreeSet<Point>(yC); // Creates empty tree set closestLeft = xQueue[0]; closestRight = xQueue[1]; delta = distance(closestLeft, closestRight); yTree.add(xQueue[0]); yTree.add(xQueue[1]); c = 2; t = 0; n = xQueue.length; while ( c < n ) { current = xQueue[c]; while ( t < c && (double)(current.x - xQueue[t].x) >= delta) { if ( yTree.remove(xQueue[t])) System.out.println("REMOVED ----> " + xQueue[t].x + ":" + xQueue[t].y); t = t + 1; }
- 05-02-2009, 03:13 AM #2
Member
- Join Date
- Jan 2009
- Posts
- 9
- Rep Power
- 0
Disregard this I messed with the comparator in a weird way and it affected the remove method. Curious why if anybody knows.
- 05-02-2009, 04:01 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
I would expect yTree.remove() to return false becuase, as the comment in your code notes, you create an empty tree. You add the end points from the array but no other points.
Even if you "add" the other points whether they are actually added (and therefore whether remove() will return true) is going to depend on how you implement the comparator. See my reply in your other thread.
Similar Threads
-
trouble in removing a value
By jacline in forum New To JavaReplies: 5Last Post: 03-20-2009, 05:56 PM -
TreeSet Demonstration
By Java Tip in forum java.langReplies: 0Last Post: 04-15-2008, 07:34 PM -
Working with HashSet and TreeSet
By Java Tip in forum java.langReplies: 0Last Post: 04-15-2008, 07:34 PM -
ClassCastException in TreeSet
By pHew in forum New To JavaReplies: 2Last Post: 01-16-2008, 12:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks