0

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;	
	    	}
	
		  }
		}
	}     
2
Contributors
1
Reply
13
Views
12 Years
Discussion Span
Last Post by alpe gulay
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.