Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
21
Task/Quickselect-algorithm/Icon/quickselect-algorithm.icon
Normal file
21
Task/Quickselect-algorithm/Icon/quickselect-algorithm.icon
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
procedure main(A)
|
||||
every writes(" ",select(1 to *A, A, 1, *A)|"\n")
|
||||
end
|
||||
|
||||
procedure select(k,A,min,max)
|
||||
repeat {
|
||||
pNI := partition(?(max-min)+min, A, min, max)
|
||||
pD := pNI - min + 1
|
||||
if pD = k then return A[pNI]
|
||||
if k < pD then max := pNI-1
|
||||
else (k -:= pD, min := pNI+1)
|
||||
}
|
||||
end
|
||||
|
||||
procedure partition(pivot,A,min,max)
|
||||
pV := (A[max] :=: A[pivot])
|
||||
sI := min
|
||||
every A[i := min to max-1] <= pV do (A[sI] :=: A[i], sI +:= 1)
|
||||
A[max] :=: A[sI]
|
||||
return sI
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue