QUOTE(zvezdas @ 14 Feb, 2008 - 03:22 PM)

I am having problems with understanding the insertion sort this is the homework that i have to do.
public static <E extends Comparable<? super E>> int insertionSort (List<E> list, int start, int end)
This method sorts the elements in a subrange of a list using insertion sort. The elements from index start to index end (inclusive) are sorted, other elements in the list are unchanged. The method returns the number of comparisons that were made during the sorting operation.
Your code will be similar to the code in figure 8.2 on page 306 of the book, except for three changes: First, the elements are in a list, not an array, so to access the elements you will use list.get(index) and list.set(index, element). Second, you will be sorting a sublist, so you will not start or stop your loops with the same indices as in figure 8.2. Instead, you will adapt the loops to use the start and end method parameters. Third, you need to count and return the number of element comparisons that are made during the sort. Only count comparisons between elements, do not count comparisons involving indices or other primitives.
Note that this method uses the generic type variable E to specify the element type, and that it guarantees that objects of type E are comparable. You do not need to do anything special in your method, just use type E whenever you declare variables to hold list elements. (In the figure in the book they named their type parameter AnyType instead of E.)
And this is what i got so far. i don't know what i am doing wrong.
package assignment04;
import java.util.List;
public class insertion
{
public static <E extends Comparable<? super E>> int insertionSort (List<E> list, int start, int end)
{
for(start = 1; start < list.get(index); start++)
{
E tmp = list.set(index, element);
int j = start;
for(; j > 0 && tmp.compareTo(a[j - 1]) < 0; j--)
a[ j ] = a[ j - 1];
a[ j ] = tmp;
}
}
}
Hey, are you CS2420? Looks like it, I think I'm in your class and am having the exact same problems.
And the deadline is fast apraoching...