Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int[] selectionSort(int ... numbers) {
- int pos, value;
- int[] result = numbers.clone();
- for (int i = 0; i < result.length - 1; i++) {
- value = result[i];
- pos = i;
- for (int j = i + 1; j < result.length; j++) {
- if (result[j] < value) {
- value = result[j];
- pos = j;
- }
- }
- result[pos] = result[i];
- result[i] = value;
- }
- return result;
- }
- public static int[] selectionSortWorse(int ... numbers) {
- int pos, value;
- int[] result = numbers.clone();
- for (int i = 0; i < result.length - 1; i++) {
- pos = i;
- for (int j = i + 1; j < result.length; j++) {
- if (result[j] < result[pos]) {
- pos = j;
- }
- }
- value = result[pos];
- result[pos] = result[i];
- result[i] = value;
- }
- return result;
- }
Add Comment
Please, Sign In to add comment