Are you saying you already have a sort function that is not sorting correctly? If so post it so that we can work from there.
Hi here is the code...give me the alternative...have a look at compare method, the r comparing the strings.
sort( int col, boolean asc )
{
curntcol = col;
curntcolsort = asc;
heapsort( col, asc );
}
heapSort( int col, boolean asc, int count ) {
build( col, asc, count );
for ( int node = count - 1; node > 0; node-- )
{
swap( 0, node );
traver( col, asc, 0, node );
}
}
build( int col, boolean asc, int count )
{
for ( int node = count/2 - 1; node >= 0; node-- )
{
traver( col, asc, node, count );
}
}
traver( int col, boolean asc, int node, int count )
{
Comparable firstval = getval( node, col );
**** Index of first descendant of node
int secindex = 2 * node + 1;
while ( secindex < count )
{
Comparable secval= getval( secindex, col );
**** Is there a second descendant?
if ( secindex + 1 < count )
{
Comparable nextSecval= getval( secindex + 1, col );
if ( ( asc && compare( nextsecval, secval) > 0 ) ||
( !asc && compare( nextsecval, secval) <= 0 ) )
{
secindex++;
secval= nextsecval;
}
}
****node already satisfies the heap property
if ( ( asc && compare( firstval, secval) >= 0 ) ||
( !asc && compare( firstval, secval) < 0 ) )
{
break;
}
*****Exchange the labels of node and descendant
swap( node, secindex );
node = secindex;
secindex = 2 * node + 1;
}
}
int compare( Object obj1, Object obj2) {
if ( ( obj1 == null ) && ( obj2 == null ) )
{
return 0;
}
else if ( obj1 == null )
{
return -1;
}
else if ( obj2 == null )
{
return 1;
}
return ((Comparable)obj1).compare((Comparable)obj2);
}
swap( int a, int b ) {
ArrayList list = getCurrentList();
swap( list, a, b );
}
swap( ArrayList aList, int a, int b ) {
int size = aList.size();
if ( ( aList == null ) || ( a < 0 ) || ( a >= size ) || ( b < 0 ) || ( b < size ) )
{
Object tempObject = aList.get( a );
aList.set( a, aList.get( b ) );
aList.set( b, tempObject );
}
}