-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection.java
More file actions
35 lines (35 loc) · 834 Bytes
/
selection.java
File metadata and controls
35 lines (35 loc) · 834 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
import java.util.*;
class selection
{
public static void main()
{
int ar[] = {22,8,4,11,5,78,2,7,15,44};
int i,j,temp,small,ind;
System.out.println("Unsorted array : ");
for(i = 0; i < 10; i++)
{
System.out.print(ar[i] + "\t");
}
for(i = 0; i < 10; i++)
{
small = ar[i];
ind = i;
for(j = i+1; j < 10; j++)
{
if(ar[j] < small)
{
small = ar[j];
ind = j;
}
}
temp = ar[i];
ar[i] = ar[ind];
ar[ind] = temp;
}
System.out.println("\nSorted array : ");
for(i = 0; i < 10; i++)
{
System.out.print(ar[i] + "\t");
}
}
}