Re: Sorting and removing duplicates
Shane wrote:
Patricia Shanahan wrote:
Shane wrote:
I have been asked to implement quicksort (or mergesort) in an
application, and then remove any duplicates.
I have done just that, however, I have been further told that I should
call my sort method from within my remove duplicates method.
When my methods are called independently they work perfectly. However
when I call the sort method from within the remove duplicates method, the
array returned is not sorted correctly.
...
I assume you are looking for advice on what to do next, when your
program does not do exactly what you want, and it is not obvious to you
why.
I've written a description of one approach to debug, see
http://home.earthlink.net/~patricia_shanahan/debug/
Patricia
Hi
In a way no. I do not understand why a module that works as desired
when "freestanding" is not behaving the same way when called from another
module.
....
In that situation, I would have two alternative theories:
1. A bug in the sort method that makes it fail for some inputs, but not
others.
2. A bug in how the sort method is being called when it is not
"freestanding".
You could find out which is true by replacing, just for debug purposes,
your sort with Arrays.sort. If it works with Arrays.sort, the problem is
in your sort code. If it does not work with Arrays.sort, the problem is
in how it is being called when it fails.
Patricia