Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static long gnomeSort(int[] list) {
- int pos = 1;
- int last = 0;
- int temp;
- while(pos < list.length) {
- if(list[pos] >= list[pos - 1]) {
- if(last != 0) {
- pos = last;
- last = 0;
- }
- pos += 1;
- } else {
- temp = list[pos];
- list[pos] = list[pos - 1];
- list[pos - 1] = temp;
- if(pos > 1) {
- if(last == 0) {
- last = pos;
- }
- pos -= 1;
- } else {
- pos += 1;
- }
- }
- }
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment