diff --git a/src/main/java/com/github/pedrovgs/sortingalgorithm/SortingAlgorithm.java b/src/main/java/com/github/pedrovgs/sortingalgorithm/SortingAlgorithm.java index a542538f..82f2e105 100644 --- a/src/main/java/com/github/pedrovgs/sortingalgorithm/SortingAlgorithm.java +++ b/src/main/java/com/github/pedrovgs/sortingalgorithm/SortingAlgorithm.java @@ -20,7 +20,19 @@ * * @author Pedro Vicente Gómez Sánchez. */ -public interface SortingAlgorithm { +public abstract class SortingAlgorithm { - void sort(int[] numbers); + public abstract void sort(int[] numbers); + + protected void swap(int[] numbers, int i, int j) { + int temp = numbers[i]; + numbers[i] = numbers[j]; + numbers[j] = temp; + } + + protected void validateInput(int[] numbers) { + if (numbers == null) { + throw new IllegalArgumentException("You can't pass a null instance as parameter."); + } + } }