Created
December 19, 2015 15:24
-
-
Save Yur-ok/ff00c75c31d51bbfdae9 to your computer and use it in GitHub Desktop.
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
package Lesson3.KeyPoint2; | |
import java.util.Arrays; | |
/** | |
* Created by Юрий on 18.12.2015. | |
*/ | |
public class VoidSwapSort { | |
public static void main(String[] args) { | |
int[] arr = {7, 2, 5, 4, 3, 6, 1}; | |
int[] arr2 = {7, 12, 5, 4, 443, 66, 1}; | |
int[] arr1 = new int[0]; | |
System.out.println(Arrays.toString(arr)); | |
swapSort(arr1); | |
System.out.println(Arrays.toString(arr2)); | |
} | |
static void swapSort(int[] data) { | |
if (data == null || data.length == 0) { | |
System.out.println(-1); | |
return; | |
} | |
int temp; | |
for (int idx = 0; idx < data.length -1; idx++) { | |
for (int i = 0, k = 1; (i < data.length - 1 && k <= data.length - 1); i++, k++) { | |
if (data[i] > data[k]) { | |
temp = data[i]; | |
data[i] = data[k]; | |
data[k] = temp; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Действительно по заданию сортировка не была нужна, а только перемещение наибольшего элемента массива на последнее место. Уточняйте задания.