Ordered List e BinarySearchTree
This commit is contained in:
@@ -20,16 +20,26 @@ public class OrderedListSet <E> implements Set<E> {
|
||||
|
||||
|
||||
|
||||
OrderedListSet() {
|
||||
public OrderedListSet() {
|
||||
L = new NodePositionList<E>();
|
||||
c = new DefaultComparator();
|
||||
c = new DefaultComparator<E>();
|
||||
}
|
||||
|
||||
OrderedListSet(Comparator<E> in_c) {
|
||||
public OrderedListSet(Comparator<E> in_c) {
|
||||
L = new NodePositionList<E>();
|
||||
c = in_c;
|
||||
}
|
||||
|
||||
public OrderedListSet(PositionList<E> in_l){
|
||||
L = in_l;
|
||||
c = new DefaultComparator<E>();
|
||||
}
|
||||
|
||||
public OrderedListSet(PositionList<E> in_l,Comparator<E> in_c ){
|
||||
L = in_l;
|
||||
c = in_c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -47,50 +57,59 @@ public class OrderedListSet <E> implements Set<E> {
|
||||
|
||||
|
||||
@Override
|
||||
public Set<E> union(Set<E> B) {return null;
|
||||
public Set<E> union(Set<E> B) {
|
||||
MergeUnion<E> ret = new MergeUnion<E>(L, ((OrderedListSet<E>)B).L , c );
|
||||
L = ret.getResult();
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> intersect(Set<E> B) {
|
||||
return null;
|
||||
MergeIntersect<E> ret = new MergeIntersect<E>(L, ((OrderedListSet<E>)B).L , c );
|
||||
L = ret.getResult();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> subtract(Set<E> B) {
|
||||
return null;
|
||||
MergeSubtract<E> ret = new MergeSubtract<E>(L, ((OrderedListSet<E>)B).L , c );
|
||||
L = ret.getResult();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return L.toString();
|
||||
}
|
||||
|
||||
//////////////////////// inner class override methods from merge template /////
|
||||
|
||||
protected class MergeUnion<E> extends MergeTemplate<E>{
|
||||
|
||||
public MergeUnion (PositionList<E> A , PositionList<E> B, DefaultComparator<E> c){
|
||||
public MergeUnion (PositionList<E> A , PositionList<E> B, Comparator<E> c){
|
||||
super(A,B,c);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void aIsLess(E a) {
|
||||
|
||||
s.addLast(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bIsLess(E b) {
|
||||
|
||||
s.addLast(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bothAreEqual(E a, E b) {
|
||||
|
||||
s.addLast(a);
|
||||
}
|
||||
}
|
||||
|
||||
protected class MergeIntersect<E> extends MergeTemplate<E>{
|
||||
|
||||
public MergeIntersect (PositionList<E> A , PositionList<E> B, DefaultComparator<E> c){
|
||||
public MergeIntersect (PositionList<E> A , PositionList<E> B, Comparator<E> c){
|
||||
super(A,B,c);
|
||||
}
|
||||
|
||||
@@ -106,19 +125,19 @@ public class OrderedListSet <E> implements Set<E> {
|
||||
|
||||
@Override
|
||||
protected void bothAreEqual(E a, E b) {
|
||||
|
||||
s.addLast(a);
|
||||
}
|
||||
}
|
||||
|
||||
protected class MergeSubtract<E> extends MergeTemplate<E>{
|
||||
|
||||
public MergeSubtract (PositionList<E> A , PositionList<E> B, DefaultComparator<E> c){
|
||||
public MergeSubtract (PositionList<E> A , PositionList<E> B, Comparator<E> c){
|
||||
super(A,B,c);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void aIsLess(E a) {
|
||||
|
||||
s.addLast(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user