This is my code so far. I need help to implement a main method that reads and sorts the supplied test files(unsorted1.txt and unsorted2.txt)
public class quickSort extends DLList {
public static <E extends Comparable <? super E>> void quickSort(DLList<E> element){
sort(element, 0, element.size() - 1);
}
public static <E extends Comparable <? super E>> void sort(DLList<E> element, int l, int r) {
int i = l;
int j = r;
E pivot = element.get((l + r) / 2), w;
do {
while (element.get(i).compareTo(pivot)< 0){
++i;
}
while (element.get(j).compareTo(pivot)> 0){
--j;
}
while (i <= j) {
w = element.get(i);
element.set(i, element.get(j));
element.set(j, w);
++i;
--j;
}
} while (i <= j);
if (l < j) {
sort(element, l, j);
}
if (i < r) {
sort(element, i, r);
}
}
public static void main(String[] args){
}
My quicksort implementation is complete and it is based on a doubly linked list. The text files contain a number of unsorted characters. So I have to load all characters and store them in the list. And that's what I need help with.
Can you please elaborate a little more on files part?
What is the data format in the file? Should the output format after sorting be the same as input format?
As much as i understand your quicksort implementation is ready, all that you need is to parse the text file and sort and write it back to the file.