Last active
January 14, 2016 13:32
-
-
Save Yur-ok/795e7dd5ab435d9a5b4c 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.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; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Сортировка не в том направлении.