Birel Chowdhury wrote:Please give me the java code.
Seetharaman Venkatasamy wrote:do you think that is possible without traversing the whole list ?
track of max number every time I push or pop
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:unless you maintain a sorted list
Birel Chowdhury wrote: Does my previous max() method look ok for push?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Birel Chowdhury wrote:
I am only allowed to pass int primitives in my push or pop method in driver class. How can I implement object here?
Birel Chowdhury wrote:Give me some thoughts for pop method. Some code or psuedocode please. Thanks
frosenberger wrote:unless you maintain a sorted list
Mike Simmons wrote:I would suggest a PriorityQueue instead
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:
Mike Simmons wrote:I would suggest a PriorityQueue instead
I guess that is another question that needs to be answered. As I understand, a PriorityQueue will always return the least element.
fred rosenberger wrote:That may not work if you need the elements popped off in the order they were pushed, but ALSO need to know the maximum buried in there...somewhere...
Junilu Lacar wrote:On the other hand, the explicit mention of emphasizing speed still makes me think that the "value+height" interpretation of "find" was what the instructor had in mind.