forked from anandpatel88/JavaPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortUsingSelection.java
More file actions
39 lines (30 loc) · 849 Bytes
/
Copy pathSortUsingSelection.java
File metadata and controls
39 lines (30 loc) · 849 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
27
28
29
30
31
32
33
34
35
36
37
38
39
/*The selection sort is a combination of searching and sorting. During each pass,
the unsorted element with the smallest (or largest) value is moved to its proper
position in the array. The number of times the sort passes through the array is one
less than the number of items in the array. In the selection sort, the inner loop finds
the next smallest (or largest)
value and the outer loop places that value into its proper location.*/
package JavaPgm;
public class SortUsingSelection {
public static void main(String[] args)
{
int[] a={5,6,4,3,7,8,9,10,12,2,1};
int l=a.length;
for(int i=0;i<l;i++)
{
for(int j=0;j<l;j++)
{
if(a[i]<a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(int k:a)
{
System.out.println(k);
}
}
}