SP
мне пришлось делать в двух случаях
(idx + 1)..idx1.clone()
idx..&(idx.clone() + 1)
Size: a a a
SP
SP
SP
SP
С
OA
import qualified Data.Vector.Generic as V
import qualified Data.Vector.Generic.Mutable as M
qsort :: (V.Vector v a, Ord a) => v a -> v a
qsort = V.modify go where
go xs | M.length xs < 2 = return ()
| otherwise = do
p <- M.read xs (M.length xs `div` 2)
j <- M.unstablePartition (< p) xs
let (l, pr) = M.splitAt j xs
k <- M.unstablePartition (== p) pr
go l; go $ M.drop k pr
ΑZ
ΑZ
ΑZ
ΑZ
C
C
С
ΑZ
С
H
datatype(
BinaryTree,
(Leaf, int),
(Node, struct BinaryTree *, int, struct BinaryTree *)
);
int sum(const BinaryTree *tree) {
match(*tree) {
of(Leaf, x) {
return *x;
}
of(Node, lhs, x, rhs) {
return sum(*lhs) + *x + sum(*rhs);
}
}
}
DS
datatype(
BinaryTree,
(Leaf, int),
(Node, struct BinaryTree *, int, struct BinaryTree *)
);
int sum(const BinaryTree *tree) {
match(*tree) {
of(Leaf, x) {
return *x;
}
of(Node, lhs, x, rhs) {
return sum(*lhs) + *x + sum(*rhs);
}
}
}
H
enum { LeafTag, NodeTag }
DS
enum { LeafTag, NodeTag }
H