aspose file tools
The moose likes Beginning Java and the fly likes duplicate values in sort Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "duplicate values in sort" Watch "duplicate values in sort" New topic
Author

duplicate values in sort

Senaca Boyd
Greenhorn

Joined: Feb 21, 2007
Posts: 9
If I have an array that is not sorted and contains duplicate values, which of these sorting techniques will successfully accomplish my sort: heap sort, selection sort, or bubble sort?
[ April 05, 2007: Message edited by: Senaca Boyd ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10040
    
    6

what do you mean by "successfully accomplish my sort"? all of these techniques will sort the array.

could you be more specific in your question?


Never ascribe to malice that which can be adequately explained by stupidity.
Senaca Boyd
Greenhorn

Joined: Feb 21, 2007
Posts: 9
I thought there were some sort techniques that would not work if one of the values being sorted was a duplicate. Am I wrong?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10040
    
    6

i don't remember which of these are which, but there is the concept of a 'stable' vs. 'unstable' sort.

this concept relates to how you handle two items with the same key. in a stable sort, the pre-sort order of items with the same key is preserved. an unstable sort makes no garantees either way.

this is more of an issue when you are sorting on multiple fields - say first and last name. if i sort by first name first, when i then sort by last name, i want to keep all the smiths in the order they came to me.

I don't know if that is what you were thining of or not. but if you are sorting on a single element, the sort algorithm shouldn't matter.

some may be more or less efficient, but again, i don't think that is what you were aiming towards
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: duplicate values in sort
 
Similar Threads
Sorting Hashtable
HashMap sorting
HashSet
Duplicate keys in Hashmap returns null get("key")
how do I validate a listbox