Created
June 7, 2014 19:24
-
-
Save xrigau/13d3dfb12ad9820e5222 to your computer and use it in GitHub Desktop.
Sorting Algorithms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface SortingAlgorithm { | |
int[] sort(int[] values); | |
} | |
class QuickSort implements SortingAlgorithm { | |
@Override | |
int[] sort(int[] values) { | |
return quickSort(values); | |
} | |
// ... | |
} | |
class MergeSort implements SortingAlgorithm { | |
@Override | |
int[] sort(int[] values) { | |
return mergeSort(values); | |
} | |
// ... | |
} | |
class SortingAlgorithmFactory() { | |
SortingAlgorithm newAlgorithm(Type type) { | |
switch (type) { | |
case QUICKSORT: | |
return new QuickSort(); | |
case MERGESORT: | |
return new MergeSort(); | |
default: | |
throw new IllegalArgumentException("Invalid type"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment