import java.util.ArrayList;
import java.util.Collections;
class InsertionSort
{
public Object insertionSort(Object array[], int startIdx, int endIdx)
{
for (int i = startIdx; i < endIdx; i++)
{
int k = i;
for (int j = i + 1; j < endIdx; j++)
{
if ((array[k]).compareTo(array[j])>0)
{
k = j;
}
}
Collections.swap(array,i,k);
}
return array;
}
public static void main(String args[])
{
String[] array = {"David","Luiz","Pedro"};
InsertionSort is = new InsertionSort();
System.out.println((String)is.insertionSort(array,0,7));
}
}
Erro
C:\Documents and Settings\David\Desktop\Java>javac InsertionSort.java -Xlint
InsertionSort.java:13: warning: [unchecked] unchecked call to compareTo(T) as a
member of the raw type java.lang.Comparable
if (((Comparable) array[k]).compareTo(array[j])>
0)
^
InsertionSort.java:18: swap(java.lang.Object[],int,int) has private access in ja
va.util.Collections
Collections.swap(array,i,k);
^
1 error
1 warning