Lio Liov wrote:Thanks
This is the error message.Can I specify by what member variable the object should be comapred
Exception in thread "main" java.lang.ClassCastException: Practice.Obj cannot be cast to java.lang.Comparable
Lio Liov wrote:Thanks for your time.
Apperenty I can not.
I am asking for help politely (not for sarcasm)
Lio Liov wrote:Thank you for your time.
Maybe from the position of person knowing Java,it is hard for you to be on the other side(person tring to learn Java)
Of course first I am googling ,and try to read the docs .But sometimes is confusing!!!And then I am asking for help.
And on my code again
If I want to put this priority queue in order,I have to use comparable to point what argument to compare,and then what
(do I have to do the swap)
Lio Liov wrote:This is what I did so far .Am I going in the right direction.
do I have to do the swap
Lio Liov wrote:Do you have to run a loop (to compare the ojbects and put them in the right position)
You said that the queue will perform the operation,Could you show me with code how can I do that
Lio Liov wrote:
Still problem with the priority queue.Compilation error
Lio Liov wrote:Apperenty I don know how to connect comparator with priority queue
The error is in QueueExample class the line with expanation mark comments
Thanks
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Obj cannot be resolved to a variable
NumberComparator cannot be resolved to a variable
at Practice.QueueExample.main(QueueExample.java:10)
Lio Liov wrote:
Why the previous code was not printing the queue in the right order
The Iterator provided in method iterator() is not guaranteed to traverse the elements of the priority queue in any particular order. If you need ordered traversal, consider using Arrays.sort(pq.toArray()).
Your buns are mine! But you can have this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|