Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

does this sort an array of integers?

 
alaina peeler
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, only objects. But why not use java.util.Arrays.sort()?
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic