50% OFF!!!

Thursday, September 3, 2009

J2ME | String array sort

Here is a good function for sorting string arrays.
The algorithem is BUBBLE-SORT algorithm.
The algorithem sorts the string array (dictionary comparison)


static void bubbleSort(String[] p_array) throws Exception
{
boolean anyCellSorted;
int length = p_array.length;
String tmp;
for (int i = length; --i >= 0;)
{
anyCellSorted = false;
for (int j = 0; j < i; j++)
{
if (p_array[j].compareTo(p_array[j + 1]) > 0)
{
tmp = p_array[j];
p_array[j] = p_array[j + 1];
p_array[j + 1] = tmp;
anyCellSorted = true;
}

}
if (anyCellSorted == false)
{
return;
}
}
}



if you want i will upload more SORT algorithems...

No comments:

Post a Comment