Skip to content

Commit c07872e

Browse files
author
8h
committed
First Commit
1 parent 2b72593 commit c07872e

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
### Sorting
88

99
* BubbleSort - ✅
10-
* Selection Sort
10+
* Selection Sort - ✅
1111

1212
## Data Structures
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.algorithms.sort;
2+
3+
public class SelectionSort {
4+
5+
public static void main(String[] args) {
6+
7+
int[] array = {10,8,100,3,5,2,1,10};
8+
SelectionSort selectionSort = new SelectionSort();
9+
int[] sorted = selectionSort.selectionSort(array);
10+
11+
for(int i=0; i<sorted.length;i++) {
12+
System.out.println(sorted[i]);
13+
}
14+
15+
}
16+
17+
public int[] selectionSort(int[] array) {
18+
19+
int min=0;
20+
int temp=0;
21+
for(int i=0; i<array.length;i++) {
22+
23+
min = i;
24+
for(int j=i+1; j<array.length;j++) {
25+
26+
if(array[min] > array[j]) {
27+
min = j;
28+
}
29+
30+
}
31+
if(min!=i) {
32+
temp = array[i];
33+
array[i] = array[min];
34+
array[min] = temp;
35+
}
36+
37+
}
38+
39+
40+
return array;
41+
}
42+
43+
}

0 commit comments

Comments
 (0)