@@ -0,0 +1,1202 @@
+package sortingalgorithms;%0A%0A/**%0A *  An implementation of Shellsort. It uses Marcin Ciura's gap sequence%0A *  per default.%0A *%0A *  @author  Joel Abrahamsson%0A *  @version %25G%25%0A */%0Apublic class ShellSort implements SortingAlgorithm%0A%7B%0A  // Marcin Ciura's gap sequence%0A  private int%5B%5D gaps = %7B701, 301, 132, 57, 23, 10, 4, 1%7D;%0A%0A  public static ShellSort sorter = new ShellSort();%0A%0A  protected ShellSort()%0A  %7B%0A  %7D%0A%0A  /**%0A   *  Returns the gap sequence.%0A   *%0A   *  @return the gap sequence%0A   */%0A  public int%5B%5D getGapSequence()%0A  %7B%0A    return gaps;%0A  %7D%0A%0A  /**%0A   *  Changes the gap sequence to the given sequence.%0A   *%0A   *  @param gaps new gap sequence%0A   */%0A  public void setGapSequence(int%5B%5D gaps)%0A  %7B%0A    if (gaps != null && gaps.length %3E 0)%0A      this.gaps = gaps;%0A  %7D%0A%0A  /**%0A   *  Sorts the given array using Shellsort.%0A   *%0A   *  @param array array to be sorted%0A   */%0A  public void sort(int%5B%5D array)%0A  %7B%0A    int length = array.length;%0A%0A    for (int gap : gaps)%0A    %7B%0A      for (int i = 0; i %3C length; i++)%0A      %7B%0A        int temp = array%5Bi%5D,%0A            j = i;%0A        for (; j %3E= gap && array%5Bj - gap%5D %3E temp; j -= gap)%0A          array%5Bj%5D = array%5Bj - gap%5D;%0A%0A        array%5Bj%5D = temp;%0A      %7D%0A    %7D%0A  %7D%0A%7D%0A

Implement Shellsort