Sorts.java

Gnome Sort In this exercise, you will learn about the Gnome Sort, which was named by its inventor Hamid Sarbazi-Azad as the Stupid Sort}. What is interesting is that our quadratic sorts have an inner and outer loop. This has a single loop. Here is the idea.

  1. If the list has fewer than two items, you are done. Otherwise proceed as follows.
  2. Start at the beginning of the list.
  3. Move right one.
  4. Check your value and the value to the left. If they are in order, move right one.
  5. If they are out of order, swap them and move one to the left. If you are at the beginning, move right one.
  6. Once you skid off the right hand end of the list, you are done.

You will also implemenent the zip method and mergesort in Java.


import java.util.List;
import java.util.ArrayList;
public class Sorts
{
    public static <T extends Comparable> void gnome(List<T> x)
    {
    }
    private static <T extends Comparable> List<T> zipper(List<T>a, List<T> b)
    {
        return null;
    }
    public static <T extends Comparable> void merge(List<T> x)
    {
    }
}