package sorters;

import java.util.ArrayList;

public class GnomeSorter<T extends Comparable<T>> extends Sorter<T> {

	@Override
	protected void sortAlgorithm(ArrayList<T> array) {
		int i = 0;
		while (i < array.size() - 1) {
			if (array.get(i).compareTo(array.get(i+1)) > 0) {
				swap(array, i, i+1);
				i = Math.max(0, i-1);
			} else {
				i += 1;
			}
		}
	}
}
