Start New Discussion within our Software Development Community

Here is a code to sort numbers instead of strings using the BubbleSort method. The difference here is you don't use compareTo() for numbers as you do with strings.

public class SortArrayNumbers
{
public static void sortEm(int [] array, int len)
	{
		int a,b;
	    int temp;
		int sortTheNumbers = len - 1;
		for (a = 0; a < sortTheNumbers; ++a)
		{
		for (b = 0; b < sortTheNumbers; ++b)
		if(array[b] < array[b + 1])
		{
		  temp = array[b];
		  array[b] = array[b + 1];
		  array[b + 1] = temp;	
	    	}
	
		  }
		}
	}