lab/lab12/MergeSort.java
public static <Item extends Comparable> Queue<Item> mergeSort(
            Queue<Item> items) {

        if (items.size() == 1) {
            return items;
        } else if (items.size() == 2) {
            Queue<Queue<Item>> qq = makeSingleItemQueues(items);
            return mergeSortedQueues(qq.dequeue(), qq.dequeue());

        } else {
            Queue<Item> tmp1 = new Queue<>();
            Queue<Item> tmp2 = new Queue<>();
            int i = 0;

            for (Item item : items) {
                if (i % 2 == 0) {
                    tmp1.enqueue(item);
                } else {
                    tmp2.enqueue(item);
                }
                i += 1;
            }

            return mergeSortedQueues(mergeSort(tmp1), mergeSort(tmp2));
        }

    }
/** Returns a Queue that contains the given items sorted from least to greatest. */
Returns a Queue that contains the given items sorted from least to greatest.
Returns a Queue that contains the given items sorted from least to greatest .
public static <Item extends Comparable> Queue<Item> mergeSort(
            Queue<Item> items) {
        if (items.size() == 1) {
            return items;
        } else if (items.size() == 2) {
            Queue<Queue<Item>> qq = makeSingleItemQueues(items);
            return mergeSortedQueues(qq.dequeue(), qq.dequeue());
        } else {
            Queue<Item> tmp1 = new Queue<>();
            Queue<Item> tmp2 = new Queue<>();
            int i = 0;
            for (Item item : items) {
                if (i % 2 == 0) {
                    tmp1.enqueue(item);
                } else {
                    tmp2.enqueue(item);
                }
                i += 1;
            }
            return mergeSortedQueues(mergeSort(tmp1), mergeSort(tmp2));
        }
    }
public static < Item extends Comparable > Queue < Item > mergeSort ( Queue < Item > items ) { if ( items . size ( ) == 1 ) { return items ; } else if ( items . size ( ) == 2 ) { Queue < Queue < Item > > qq = makeSingleItemQueues ( items ) ; return mergeSortedQueues ( qq . dequeue ( ) , qq . dequeue ( ) ) ; } else { Queue < Item > tmp1 = new Queue < > ( ) ; Queue < Item > tmp2 = new Queue < > ( ) ; int i = 0 ; for ( Item item : items ) { if ( i % 2 == 0 ) { tmp1 . enqueue ( item ) ; } else { tmp2 . enqueue ( item ) ; } i += 1 ; } return mergeSortedQueues ( mergeSort ( tmp1 ) , mergeSort ( tmp2 ) ) ; } }
Returns a Queue that contains the given items sorted from least to greatest.
Returns a Queue that contains the given items sorted from least to greatest .