Julia samples (#108)
* Add julialang binary search sample * Add unit test * Add julialang selection sort sample * Change julia suffix to jl * Add recursion and quick sort with tests * add quick sort * Add hash table samples * Add BFS * Changed file names * Add dijkstras * Add Dijkstras test
This commit is contained in:
committed by
Aditya Bhargava
parent
30bbe9cf01
commit
9dc7611411
26
02_selection_sort/julia/01_selection_sort.jl
Normal file
26
02_selection_sort/julia/01_selection_sort.jl
Normal file
@@ -0,0 +1,26 @@
|
||||
using Test
|
||||
|
||||
function find_smallest(arr)
|
||||
smallest = arr[1]
|
||||
smallest_index = 1
|
||||
for i = 1:length(arr)
|
||||
if arr[i] < smallest
|
||||
smallest = arr[i]
|
||||
smallest_index = i
|
||||
end
|
||||
end
|
||||
return smallest_index
|
||||
end
|
||||
|
||||
function selection_sort(arr)
|
||||
new_arr = Array{Int64}(undef,0)
|
||||
for i = 1:length(arr)
|
||||
smallest = find_smallest(arr)
|
||||
append!(new_arr,arr[smallest])
|
||||
deleteat!(arr,smallest)
|
||||
end
|
||||
return new_arr
|
||||
end
|
||||
|
||||
arr = [5,3,6,2,10]
|
||||
@test selection_sort(arr) == [2,3,5,6,10]
|
||||
Reference in New Issue
Block a user