2 posts in topic
Flat View  Flat View

Posted By:   Anonymous
Posted On:   Monday, June 11, 2007 06:20 AM

How can we sort an array of objects not using comparator and comparable interfaces

Re: sorting

Posted By:   Robert_Lybarger  
Posted On:   Monday, June 11, 2007 06:37 PM

If array[j] value is comparatively less than array[i] value, then:

temp = array[j];
array[j] = array[i];
array[i] = temp;

For the most naive algorithm possible, for an array of size N, start looping i=0 to (N-1) and j=(i+1) to N, nested-loop fashion. Compare values and swap if needed, as above. Caution: this is the slowest, worst possible way to code a sort routine ... entire series of college classes exist to explore the faster ones.

Re: sorting

Posted By:   WarnerJan_Veldhuis  
Posted On:   Monday, June 11, 2007 07:08 AM

Sort em yourself then. Compare the properties that you need to sort on and move then to their new locations.

If you are looking for sorting algorithms, google will be your friend.
About | Sitemap | Contact