Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sort/selection.jule
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
fn Selection[T: ordered](mut arr: []T): []T {
mut i := 0
for i < len(arr); i++ {
mut minIdx := i
mut j := i + 1
for j < len(arr); j++ {
if arr[j] < arr[minIdx] {
minIdx = j
}
}
if minIdx != i {
arr[i], arr[minIdx] = arr[minIdx], arr[i]
}
}
return arr
}
5 changes: 5 additions & 0 deletions sort/testcases_test.jule
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ fn testShell(t: &testing::T) {
testGeneral(t, Shell[int])
}

#test
fn testSelection(t: &testing::T) {
testGeneral(t, Selection[int])
}

#test
fn testQuicksort(t: &testing::T) {
testGeneral(t, Quicksort[int])
Expand Down
Loading