Ordered List e BinarySearchTree
This commit is contained in:
@@ -19,8 +19,8 @@ import java.util.Iterator;
|
||||
*/
|
||||
public abstract class MergeTemplate<E> {
|
||||
|
||||
PositionList<E> s = new NodePositionList<E>();
|
||||
Comparator<E> c = null;
|
||||
protected PositionList<E> s = new NodePositionList<E>();
|
||||
protected Comparator<E> c = null;
|
||||
|
||||
public MergeTemplate (PositionList<E> A, PositionList <E> B){
|
||||
this(A,B,new DefaultComparator<E>());
|
||||
@@ -29,29 +29,49 @@ public abstract class MergeTemplate<E> {
|
||||
public MergeTemplate (PositionList<E> A, PositionList <E> B, Comparator<E> in_c){
|
||||
|
||||
c = in_c;
|
||||
E a,b;
|
||||
E a = null ,b = null;
|
||||
Iterator<E> Ait, Bit;
|
||||
Ait = A.iterator();
|
||||
Bit = B.iterator();
|
||||
|
||||
while (!(Ait.hasNext()) && !(Bit.hasNext())) {
|
||||
|
||||
if ( Ait.hasNext() && Bit.hasNext() ){
|
||||
a = Ait.next();
|
||||
b= Bit.next();
|
||||
b = Bit.next();
|
||||
for (; true; ) {
|
||||
|
||||
if ( c.compare(a,b) < 0 )
|
||||
aIsLess(a);
|
||||
else if (c.compare(a,b) > 0)
|
||||
bIsLess(b);
|
||||
else // se b = a
|
||||
bothAreEqual(a, b);
|
||||
if (c.compare(a, b) < 0) {
|
||||
aIsLess(a);
|
||||
if (Ait.hasNext())
|
||||
a = Ait.next();
|
||||
else
|
||||
break;
|
||||
} else {
|
||||
if (c.compare(a, b) > 0) {
|
||||
bIsLess(b);
|
||||
if (Bit.hasNext())
|
||||
b = Bit.next();
|
||||
else
|
||||
break;
|
||||
|
||||
} else {// se b = a
|
||||
bothAreEqual(a, b);
|
||||
if (Ait.hasNext() && Bit.hasNext()) {
|
||||
a = Ait.next();
|
||||
b = Bit.next();
|
||||
} else
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
while (!(Ait.hasNext())) {
|
||||
while ( Ait.hasNext() ) {
|
||||
a = Ait.next();
|
||||
aIsLess(a);
|
||||
}
|
||||
while (!(Bit.hasNext())) {
|
||||
while ( Bit.hasNext()) {
|
||||
b = Bit.next();
|
||||
bIsLess(b);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user