Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SelectionSort
- {
- public static void main(String[]args)
- {
- int a[]={8,5,9,6,3,4,2,1,7,5};
- int i=0;
- while(i<a.length-1)
- {
- int tmp=i;
- for(int j=i+1;j<a.length;j++)
- {
- if(a[j]<a[tmp])
- tmp=j;
- }
- int hlp=a[i];
- a[i]=a[tmp];
- a[tmp]=hlp;
- i++;
- }
- // mencetak hasil
- for(int h=0;h<a.length;h++)
- {
- System.out.println(a[h]+",");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment