forked from LalinduWenasara/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.java
More file actions
35 lines (30 loc) · 1023 Bytes
/
SelectionSort.java
File metadata and controls
35 lines (30 loc) · 1023 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
package selectionsort;
public class SelectionSort {
public static void selectionSort(int[] arr){
for (int i = 0; i < arr.length - 1; i++)
{
int in = i;
for (int k = i + 1; k < arr.length; k++){
if (arr[k] < arr[in]){
in = k;
}
}
int sNumber = arr[in];
arr[in] = arr[i];
arr[i] = sNumber;
}
}
public static void main(String a[]){
int[] ar = {30,25,66,100,1,89,174,23,77,91,3};
System.out.println("Input Values before sorting");
for(int i:ar){
System.out.print(i+" ");
}
System.out.println();
selectionSort(ar);//sorting array using selection sort
System.out.println("Input Values After sorting");
for(int i:ar){
System.out.print(i+" ");
}
}
}