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