java - FIFO tie breaker in Comparator? -


for homework, need compare nodes based on heuristic can put them in treeset. however, when heuristic values 2 nodes equal need way break tie.

i'm not allowed modify node class provided , far can tell there aren't other values / properties of node me break tie i'm not using. (we're dealing puzzles, not matters.) there way break ties based on when added them treeset? don't know how go it....

i saw example in documentation priority blocking queue want use comparator interface, , can't work.

thanks in advance; tips / hints appreciated.

are allowed create wrapper nodes?

public class nodewrapper implements comparable<nodewrapper> {   private static atomiclong serialnumgenerator = new atomiclong(0l);    private final node node;   private final long serialnum;    public nodewrapper(node node) {     this.node = node;     this.serialnum = serialnumgenerator.getandincrement();   }    @override   public int compareto(nodewrapper other) {     int compare = this.node.compareto(other.node);     if (compare == 0) {       compare = (this.serialnum < other.serialnum)           ? -1           : ((this.serialnum > other.serialnum) ? 1 : 0);     }     return compare;   }   // implement other methods including equals() , hashcode() } 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -