• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

does this sort an array of integers?

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}
}
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, only objects. But why not use java.util.Arrays.sort()?
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic