java - isConsecutive with PriorityQueue. How to +1 to Objects when comparing? -
so here original problem im working on practice it. write method called isconsecutive accepts priorityqueue of integers parameter , returns true if queue contains sequence of consecutive integers starting front of queue. far have following main problem have how "add 1" objects see if consecutive.
>
public static boolean isconsecutive(priorityqueue o){ > if(o.isempty()){ > return true; > } > while(!(o.isempty())){ > > if(o.poll() ==o.peek()){ > return true; > } > } > return false; > }
your function should take priorityqueue<integer>
object rather plain priorityqueue
. o.poll()
o.peek()
return integer
s rather plain object
s.
once have integer
s work with, can use regular +
operator.
Comments
Post a Comment