I was given a program which uses integer input to calculate Priority Queue.
How to rewrite code to represent object instead of integers?
The issue with my revision is that my modification fail to run and say
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your objects aren’t strings but integers (long). So don’t try to parse them.
You could change
to
You could also change
to
in order to avoid the cast.
But that wouldn’t work for other types of objects than Long so isn’t probably useful to you.
If you want to be able to compare any kind of object, you can provide a Comparator :
You would define
PriorityQasPriorityQ<T>(using generics), add asetComparator(Comparator comparator)method, and define your insert method like this :This means changing also the queArray array to a
T[]type.