Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Example13 {
- public void selectionSort(int[] arr) {
- int minIndex;
- int t;
- for (int i = 0; i < arr.length - 1; i++) {
- minIndex = i;
- for (int j = i + 1; j < arr.length; j++) {
- if (arr[j] < arr[minIndex]) {
- minIndex = j;
- }
- }
- t = arr[i];
- arr[i] = arr[minIndex];
- arr[minIndex] = t;
- }
- }
- }
- public class Example13_Test {
- public static void main(String[] args) {
- Example12 ob1 = new Example12();
- Example13 ob2 = new Example13();
- int[] array = new int[5];
- ob1.input(array);
- ob1.echo(array);
- ob2.selectionSort(array);
- ob1.echo(array);
- }
- }
Add Comment
Please, Sign In to add comment