Stable sorting algorithms maintain the relative order of records with equal keys. A sorting algorithm is stable if whenever there are two records R and S with the same key and with R appearing before S in the original list, R will appear before S in the sorted list.
There are two required libraries for this project, including:
- Java 8
- JUnit 4
Here is an example to use StableSort library:
final Integer FIRST_INT = 2, SECOND_INT = 1;
SortableFactory<Integer> sortableFactory = new SortableFactory<>();
// Build sortable array with helpers
Sortable<Integer>[] sortables = sortableFactory.makeSortableArray(FIRST_INT, SECOND_INT);
// Sort the array
Sortable<Integer>[] result = sorter.stableSort(sortables);
assertEquals(2, result.length);
assertEquals(SECOND_INT, result[0].getPayload());
assertEquals(1, result[0].getIndex());
assertEquals(FIRST_INT, result[1].getPayload());
assertEquals(0, result[1].getIndex());
Both Eclipse and Intellij are supported to run the unit tests.
- Fork it!
- Create your feature branch: git checkout -b new-feature
- Commit your changes: git commit -am 'Add new feature'
- Push to the branch: git push origin new-feature
- Submit a pull request :D
Yang Liu ( Harry ) from Worcester Polytechnic Institute
GPL