I am doing a project for my Data Structures class where I must implement a Shell Sort algorithm on a Linked List. We did this previously using an Array List, and when given an input of 10,000 random integers, it took my program an average of 0.012 seconds to sort the list. Now that I have implemented that same algorithm using a Linked List DS that I made it averages around 20.1 seconds (yikes). I'm wondering whether this is normal, or if it has something to do with the implementation itself? Here's the main portion of the algorithm, using Knuth's sequence as the gap values:
while(k >= 1) {
for (int i = k; i < theList.size(); i++) {
int j = i;
while (j >= k && theList.get(j - k).compareTo(theList.get(j)) > 0) {
T smaller = theList.delete(j);
theList.add(j - k, smaller);
T larger = theList.delete(j - k + 1);
theList.add(j, larger);
j -= k;
}
}
I tried using a swap method to swap the two values being compared and that didn't seem to do much. I also tried refactoring my get(), add(), and delete() methods for the LinkedList but that didn't really do anything either.