here you will a good example on java sorting algorithm application
http://javacodespot.blogspot.com/2010/08/java-sorting-animations.html
http://javacodespot.blogspot.com/
// the build in sorting functions in Java will sort pretty much any array // of Comparable objects or primitives Arrays.sort(someArray);
Java has a very efficient built in implementation of quick sort. You can use it on any array of primitives or Comparable Objects by invoking Arrays.sort(<array>) See related link.
Internal sorting it means we are arranging the number within the array only which is in computer primary memory. External sorting it is the sorting of numbers from the external file by reading it from secondary memory.
array example in java
You can also use the Collections.sort() method to sort values in an array list. You can also use the Comparable Interface or Comparators for providing custom implementations of sorting algorithms for values inside an ArrayList.
public class BubbleSortAscendingOrderDemo { public static void main(String a[]) { //Numbers which need to be sorted int numbers[] = {23,5,23,1,7,12,3,34,0}; //Displaying the numbers before sorting System.out.print("Before sorting, numbers are "); for(int i = 0; i < numbers.length; i++) { System.out.print(numbers[i]+" "); } System.out.println(); //Sorting in ascending order using bubble sort bubbleSortInAscendingOrder(numbers); //Displaying the numbers after sorting System.out.print("Before sorting, numbers are "); for(int i = 0; i < numbers.length; i++) { System.out.print(numbers[i]+" "); } }
The built in array sorting algorithm (java.util.Arrays.sort) depends on the type of data being sorted. Primitive types are sorted with a modified implementation of quicksort. Objects are sorted with a modified implementation of mergesort.
The simplest would be to put the numbers into an int[] (integer array) and pass that to java.util.Arrays.sort(int[]) (a static method), which will sort the array in ascending numerical order. Use a float[] or double[] if you need to sort non-whole numbers. You can also use the Collections.sort(List) method to sort the List directly. Or the Collections.sort(List, Comparator) if you wish to specify your own sorting criteria.
Sorting an array.
You don't need an array for that. Just do the multiplication, for example: result = factor1 * factor2; Or: result = 5 * 8;
void bubblesort (int* array, int size) { if (!array size<2) return; int last_swap = size; while (last_swap>0) { int n=last_swap; for (int i=1; i<last_swap; ++i) { if (array[i]<array[i-1]) { array[i]^=array[i-1]^=array[i]^=array[i-1]; n=i; } last_swap = n; } }
// Let's assume we're sorting the characters in String toSort // convert the String to an array of characters char[] chars = toSort.toCharArray(); // let Java do the sorting for you Arrays.sort(chars); // recreate the original String with the newly sorted array of characters toSort = new String(chars);