If I was using a Set similar to this:
Set<node> s=new TreeSet<node>();
class node {
private int x;
private int y;
}
Would this be acceptable, and since it’s a TreeSet, would it also sort it?
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.
It’s not going to be able to sort it without you implementing
Comparable<Node>, and it won’t really be an appropriate for set operations until you overrideequals()andhashCode(). (You don’t have to overrideequalsandhashCodeforTreeSetto work, but it would make sense to do so.)Something like this:
(Note that by convention the class name would be
Node, notnode.)