ย ์ ํ์ ๋ ฌ ๋ฌธ์
ํ์ด
package com.quiz.selection;
import java.util.Arrays;
interface Selection {
int[] selectionSort(int[] intArray);
}
class SelectionImpl implements Selection {
@Override
public int[] selectionSort(int[] intArray) {
int getNUm = intArray.length;
for (int i = 0; i < getNUm - 1; i++) {
int num = i;
for (int j = i + 1; j < getNUm; j++) {
if (intArray[num] > intArray[j]) {
num = j;
}
}
int tmp = intArray[i];
intArray[i] = intArray[num];
intArray[num] = tmp;
System.out.println(Arrays.toString(intArray));
}
return intArray;
}
}
public class SelectionMain {
public static void main(String[] args) {
//์ด๊ธฐ ๋ฐฐ์ด
int[] intArray = {7, 3, 2, 8, 9, 4, 6, 1, 5};
int[] result = new SelectionImpl().selectionSort(intArray);
}
}
Plain Text
๋ณต์ฌ
๊ฒฐ๊ณผ
[1, 3, 2, 8, 9, 4, 6, 7, 5]
[1, 2, 3, 8, 9, 4, 6, 7, 5]
[1, 2, 3, 8, 9, 4, 6, 7, 5]
[1, 2, 3, 4, 9, 8, 6, 7, 5]
[1, 2, 3, 4, 5, 8, 6, 7, 9]
[1, 2, 3, 4, 5, 6, 8, 7, 9]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Plain Text
๋ณต์ฌ