Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -0,0 +1 @@
|
|||
sort!(A, alg=QuickSort)
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
function quicksort!(A,i=1,j=length(A))
|
||||
if j > i
|
||||
pivot = A[rand(i:j)] # random element of A
|
||||
left, right = i, j
|
||||
while left <= right
|
||||
while A[left] < pivot
|
||||
left += 1
|
||||
end
|
||||
while A[right] > pivot
|
||||
right -= 1
|
||||
end
|
||||
if left <= right
|
||||
A[left], A[right] = A[right], A[left]
|
||||
left += 1
|
||||
right -= 1
|
||||
end
|
||||
end
|
||||
quicksort!(A,i,right)
|
||||
quicksort!(A,left,j)
|
||||
end
|
||||
return A
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
qsort(L) = isempty(L) ? L : vcat(qsort(filter(x -> x < L[1], L[2:end])), L[1:1], qsort(filter(x -> x >= L[1], L[2:end])))
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
function modes(values)
|
||||
dict = Dict() # Values => Number of repetitions
|
||||
modesArray = typeof(values[1])[] # Array of the modes so far
|
||||
max = 0 # Max of repetitions so far
|
||||
|
||||
for v in values
|
||||
# Add one to the dict[v] entry (create one if none)
|
||||
if v in keys(dict)
|
||||
dict[v] += 1
|
||||
else
|
||||
dict[v] = 1
|
||||
end
|
||||
|
||||
# Update modesArray if the number of repetitions
|
||||
# of v reaches or surpasses the max value
|
||||
if dict[v] >= max
|
||||
if dict[v] > max
|
||||
empty!(modesArray)
|
||||
max += 1
|
||||
end
|
||||
append!(modesArray, [v])
|
||||
end
|
||||
end
|
||||
|
||||
return modesArray
|
||||
end
|
||||
|
||||
println(modes([1,3,6,6,6,6,7,7,12,12,17]))
|
||||
println(modes((1,1,2,4,4)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue