pyzh / song

[又]一个硬核FP论坛;索引->type=source
https://github.com/program-in-chinese/overview/issues/68
9 stars 1 forks source link

解释APL的快排 #7

Open lg6s opened 6 years ago

lg6s commented 6 years ago

https://ruby-china.org/topics/18458

Q←{1≥≢⍵:⍵ ⋄ S←{⍺⌿⍨⍺ ⍺⍺ ⍵} ⋄ ⍵((∇<S)⍪=S⍪(∇>S))⍵⌷⍨?≢⍵}
q:{f:*x@1?#x;:[0=#x;x;,/(_f x@&x<f;x@&x=f;_f x@&x>f)]}
q:{$[2>distinct x;x;raze q each x where each not scan x < rand x]}

https://www.dyalog.com/blog/2014/12/quicksort-in-apl/ https://rosettacode.org/wiki/Sorting_algorithms/Quicksort#K https://lifeisalist.wordpress.com/2014/11/21/quicksort-in-q/

lg6s commented 6 years ago

有反馈说Q的代码不太好读,https://ruby-china.org/topics/18458#reply-346698 回头找下更好理解的版本