Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -2,9 +2,9 @@ import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
public class Merge {
public static <E extends Comparable<? super E>> List<E> mergeSort(List<E> m) {
if (m.size() <= 1) return m;
public class Merge{
public static <E extends Comparable<? super E>> List<E> mergeSort(List<E> m){
if(m.size() <= 1) return m;
int middle = m.size() / 2;
List<E> left = m.subList(0, middle);
@ -17,33 +17,35 @@ public class Merge {
return result;
}
public static <E extends Comparable<? super E>> List<E> merge(List<E> left, List<E> right) {
public static <E extends Comparable<? super E>> List<E> merge(List<E> left, List<E> right){
List<E> result = new ArrayList<E>();
Iterator<E> it1 = left.iterator();
Iterator<E> it2 = right.iterator();
E x = it1.next();
E y = it2.next();
while (true) {
while (true){
//change the direction of this comparison to change the direction of the sort
if (x.compareTo(y) <= 0) {
if(x.compareTo(y) <= 0){
result.add(x);
if (it1.hasNext())
if(it1.hasNext()){
x = it1.next();
else {
}else{
result.add(y);
while (it2.hasNext())
while(it2.hasNext()){
result.add(it2.next());
}
break;
}
} else {
}else{
result.add(y);
if (it2.hasNext())
if(it2.hasNext()){
y = it2.next();
else {
}else{
result.add(x);
while (it1.hasNext())
while (it1.hasNext()){
result.add(it1.next());
}
break;
}
}