Suppose that each object in an n-object list L is colored either
red or blue.
Give an efficient EREW algorithm to form two lists from the objects
in L: one consisting of the blue objects and
one consisting of the red objects.
Suppose that each object in an n-object list L is colored either red or blue.
Give an efficient EREW algorithm to form two lists from the objects in L: one consisting of the blue objects and other red
one consisting of the red objects.
Code:
class erew {
Property a;
Property b;
Property c;
public boolean equals(Object i) {
return i instanceof erew && a.equals(i.a) && b.equals(i.b) && c.equals(i.c);
}
public int hashCode() {
return a.hashCode() ^ b.hashCode() ^ c.hashCode();
}
public String toString() {
return a.toString() + " " + b.toString() + " " + c.toString();
}
}
Set<erew> obj= new HashSet<erew>();
for(erew i : list1) obj.add(i);
for(erew i : list2) if(obj.contains(i)) System.out.println(i + " is a match!");
Get Answers For Free
Most questions answered within 1 hours.