mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 14:34:05 +08:00
docs: update the whole repository
* fix some bugs * delete duplicate files * format code
This commit is contained in:
@ -7,19 +7,20 @@ import static Sorts.SortUtils.*;
|
||||
*
|
||||
* @author Podshivalov Nikita (https://github.com/nikitap492)
|
||||
* @since 2018-04-10
|
||||
*
|
||||
**/
|
||||
public class GnomeSort implements SortAlgorithm{
|
||||
public class GnomeSort implements SortAlgorithm {
|
||||
|
||||
@Override
|
||||
public <T extends Comparable<T>> T[] sort(T[] arr) {
|
||||
int i = 1;
|
||||
int j = 2;
|
||||
while (i < arr.length){
|
||||
if ( less(arr[i - 1], arr[i]) ) i = j++;
|
||||
while (i < arr.length) {
|
||||
if (less(arr[i - 1], arr[i])) i = j++;
|
||||
else {
|
||||
swap(arr, i - 1, i);
|
||||
if (--i == 0){ i = j++; }
|
||||
if (--i == 0) {
|
||||
i = j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,8 +28,8 @@ public class GnomeSort implements SortAlgorithm{
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] integers = { 4, 23, 6, 78, 1, 26, 11, 23 , 0, -6, 3, 54, 231, 9, 12 };
|
||||
String[] strings = {"c", "a", "e", "b","d", "dd","da","zz", "AA", "aa","aB","Hb", "Z"};
|
||||
Integer[] integers = {4, 23, 6, 78, 1, 26, 11, 23, 0, -6, 3, 54, 231, 9, 12};
|
||||
String[] strings = {"c", "a", "e", "b", "d", "dd", "da", "zz", "AA", "aa", "aB", "Hb", "Z"};
|
||||
GnomeSort gnomeSort = new GnomeSort();
|
||||
|
||||
gnomeSort.sort(integers);
|
||||
|
Reference in New Issue
Block a user