Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class SelectionSortIA{
- public static void main(String[] args) {
- int array[] = {-2,2,4,1,9,0,10};
- int temp=0;//our temp
- for (int i=0;i<array.length -1 ;i++) {
- int minIndex=i;
- for (int j=i;j<array.length-1;j++) {//checking by comparing
- if(array[j]<array[minIndex]){ //here is check
- minIndex=j; //change index minIdex if it is bigger than our
- //minIndex
- }
- }
- temp=array[i]; //swapping
- array[i]=array[minIndex];
- array[minIndex]=temp;
- }
- for (int X : array) { //just printing
- System.out.print(X+" ");
- }
- }
- }
Add Comment
Please, Sign In to add comment