I am trying to implement a simple insertion sort algorithm and make it generic to all the instance of Comparable interface.
public static <E extends Comparable<E>> void InsertionSort( E [] array)
{
for(int i = 1; i < array.length; i++)
{
E current = array[i];
int k;
for(k = i-1; k >= 0 && current.compareTo(array[k]) < 0 ; k--)
{
array[k+1] = array[k];
}
array[k+1]=current;
}
for(int l = 0; l < array.length; l++)
{
System.out.print(array[l]+" ");
}
System.out.println();
}
The problem I have is I don't know the differences between
<E extends Comparable<E>>
and
<E extends Comparable>
They both work but I don't know the reason for the first one.
<E extends Comparable<? super E>>