forked from dharmanshu1921/Java
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionsort.java
More file actions
Latest commit
26 lines (25 loc) · 722 Bytes
/
Copy pathSelectionsort.java
File metadata and controls
26 lines (25 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//selectionsort algorithm find increasing order
importjava.util.*;
publicclassselectionsort{
publicstaticvoidprintarray(intarr[]){
for(inti=0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}
System.out.println();
}
publicstaticvoidmain(Stringb[]){
intarr[]={7,8,2,3,1};
for(inti=0;i<arr.length-1;i++){
intsmallest=i;
for(intj=i+1;j<arr.length;j++){
if(arr[smallest]>arr[j]){
smallest=j;
}
}
inttemp=arr[smallest];//using swap condition
arr[smallest]=arr[i];
arr[i]=temp;
}
printarray(arr);
}
}