wood burning stoves 2.0*
The moose likes Java in General and the fly likes does this sort an array of integers? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "does this sort an array of integers?" Watch "does this sort an array of integers?" New topic
Author

does this sort an array of integers?

alaina peeler
Greenhorn

Joined: Dec 04, 2005
Posts: 29
im using selectionSort to sort an array of integers that i will create later. For example int a[MAX]; <---this will be my array. I know this sorts an array of objects, but what about integers?

public static void selectionSort(Comparable[] list)
{
int min;
Comparable temp;

for(int index=0; index<list.length-1; index++)
{ min=index;
for(int scan=index+1; scan<list.length; scan++)
if(list[scan].compareTo(list[min] < 0)
min=scan;

temp = list[min];
list[min]=list[index];
list[index]=temp;
}
}
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

No, only objects. But why not use java.util.Arrays.sort()?


[Jess in Action][AskingGoodQuestions]
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Have tested it with an int[]? If so, what types of errors are you getting?

Ernest Friedman-Hill: ...But why not use java.util.Arrays.sort()?

I'm guessing this is an assignment of some sort (bad pun intended) about implementing sorting algorithms.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: does this sort an array of integers?