0
일반 메서드를 사용하는 첫 번째 프로그램을 작업하고 있습니다. 메서드가 모든 개체의 배열을받을 수 있도록 매개 변수를 selectionSort(T[] a)
으로 설정하여 올바르게 수행하고 있다고 생각했습니다.일반 메서드 - 주어진 형식에 적용 할 수 없습니다.
public class SelectionSort {
protected int[] arrayOne = {1,2,3,4,5,6,7,8};
protected double[] arrayTwo = {1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0};
public static <T extends Comparable<T>> void selectionSort(T[] a)
{
for (int index =0; index < a.length; index++)
{
int minElementIndex = index;
T minElementValue = a[index];
for (int i = index + 1; i < a.length; i++)
{
if (a[i].compareTo(minElementValue) < 0)
{
minElementIndex = i;
minElementValue = a[i];
}
}//end of inner for loop
a[minElementIndex] = a[index];
a[index] = minElementValue;
}//end of outer for loop
for(int indexb = 0; indexb<a.length; indexb++)
{
System.out.printf("%d ", a[indexb]);
if(indexb == a.length)
System.out.println("");
}
}
public static void main(String[] args)
{
selectionSort(arrayOne);
selectionSort(arrayTwo);
}}//end of main and SelectionSort
아마도 나를 도와 줄 수 있습니다. 그렇다면 크게 감사하겠습니다.
변수를 int [] double [] 대신 Integer [] 및 Double []로 변경했지만 여전히 –
정확히 어떤 오류가 발생 했습니까? (코드를 다시 읽으면,'arrayOne'과'arrayTwo' static ...)을 만들 필요가 있다고 생각합니다. –
그 코드는 정적으로 바뀌 었습니다. –