| Author |
Sorting Arrays
|
Zak Tacc
Greenhorn
Joined: Feb 01, 2010
Posts: 25
|
|
I'm using the following code to sort a single dimensional array of strings, but any time it encounters a number, the sort resets itself. What is wrong with my code?
After sorting, the array becomes something like this:
apple
bun
cactus
elephant
zebra
13
android
babylon
zen
4
andy
band
and so on and so forth. Thanks
|
 |
pete reisinger
Ranch Hand
Joined: Dec 30, 2009
Posts: 46
|
|
Hi, you should use collection - they do the sorting for you (if they are sorted).
Check sorted set, sorted map etc.
collections
|
 |
pete reisinger
Ranch Hand
Joined: Dec 30, 2009
Posts: 46
|
|
I just checked your code and it outputs this:
13
4
android
andy
apple
babylon
band
bun
cactus
elephant
zebra
zen
The only thing I changed is method signature:
public static String[] selectionSort(String[] data) {
then of course I added return data; at the end.
If I output the array:
selectionSort(data);
for(String x : data) {
System.out.println(x);
}
it outputs the above result
|
 |
 |
|
|
subject: Sorting Arrays
|
|
|