Sort numbers

Banderson 0 Tallied Votes 166 Views Share

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;	
	    	}
	
		  }
		}
	}
alpe gulay -1 Light Poster

..thanks for this one!
it help me during our project before!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.