Sunday, December 19, 2010

Selection Sort

package utils;

public class SelectionSort {
public static void main(String a[]) {
String array[] = { "S", "D", "A", "B", "Z", "M", "O", "L", "H", "Y" };
sort(array, array.length);

System.out.println("Data items in ascending order");
for (int i = 0; i <>
System.out.print(array[i] + " ");
}

public static void sort(String array[], int n) {
for (int x = 0; x <>
int min = x;
for (int y = x; y <>
if (array[min].compareTo(array[y]) > 0) {
min = y;
}
}
String temp = array[x];
array[x] = array[min];
array[min] = temp;
}
}
}

/**
########### OUTPUT ##################
Data items in ascending order
A B D H L M O S Y Z

*/
Tag: Study Code Program Java

No comments:

Post a Comment