BACKGROUND: I want to implement a selection sort capable of handling an array list, a linked list, and a doubly linked list. For each list type I have a position{} and list{} class. The position{} class is what holds the list, (i.e. class position{int head; list tail;}). While the LIST{} contains the next(), previous(), end(), Insert(), first() methods and uses position{}, it does not contain the list class itself, the list class itself that constructs the list is called class position{}.
QUESTION: My problem is not with making the selection sort compatible, I have achieved this by only using the commands that are common between he three list abstract data types. My problem is that my selection sort returns the same list and does no sort of sorting. The list printed after the sort is the same as the list printed before the sort. Any help is appreciated.
output before selection sort 2 879 621 229 702 40 243 312 247 46 711 241 after selection sort 2 879 621 229 702 40 243 312 247 46 711 241
My list ADT's are correct, the problem lies in my poor selectionsort.
public static void SelectionSort(LIST A) {
POSITION i, j, maxp, temp;
for(i = A.Previous(A.End()); !i.isEqual(A.First()); i = A.Previous(i)) {
maxp = i;
for(j = A.First(); !j.isEqual(i); j = A.Next(j)) {
if((Integer)A.Select(j) > (Integer)A.Select(maxp)) {
maxp = j;
}
}
temp = i;
A.Insert(i, A.Select(maxp));
A.Insert(maxp, A.Select(temp));
A.Delete(maxp);
A.Delete(i);
}
}