Skip to content

Instantly share code, notes, and snippets.

@Yur-ok
Last active January 14, 2016 13:32
Show Gist options
  • Save Yur-ok/795e7dd5ab435d9a5b4c to your computer and use it in GitHub Desktop.
Save Yur-ok/795e7dd5ab435d9a5b4c to your computer and use it in GitHub Desktop.
package Lesson3.KeyPoint3;
import java.util.Arrays;
/**
* Created by Юрий on 19.12.2015.
*/
public class SortUseSwap {
public static void main(String[] args) {
int[] arr = {10, 9, 8, 7, 6};
int[] arr1 = null;
int[] arr11 = new int[0];
System.out.println(Arrays.toString(arr));
sort(arr);
System.out.println(Arrays.toString(arr));
}
static void sort(int[] data) {
if (data == null || data.length == 0) {
System.out.println(-1);
return;
}
for (int idx = 0; idx < data.length -1; idx++) {
swap(data);
}
}
static void swap(int[] data) {
int temp;
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;
}
}
}
}
@liuiv15
Copy link

liuiv15 commented Jan 14, 2016

Сортировка не в том направлении.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment