інтуітивність імперативного

Jul 24, 2016 17:29

Тут хтось поскаржився, що порядок обчислень в Х-і не зрозумілий. Ну, ось вам імперативний варіант, не обляпайтесь:

function walk2(preorder, inorder ( Read more... )

Leave a comment

Comments 8

nivanych July 24 2016, 17:18:43 UTC
> не обляпайтесь:

Кусаю крупные куски, жЫр во все стороны, вкуснотищщаа!
Ой, обляпался...
;-)

Reply


ex_juan_gan July 24 2016, 21:34:05 UTC
Well, weird; first I asked myself if we roll it all back and try to write it immutably, that is, start building the tree starting from leaves... then I figure, it was my solution (big deal, use call stack instead)

Reply

sassa_nf July 24 2016, 21:45:19 UTC
What I find weird is that the immutable solution forces you to look at it inductively. You start expressing yourself in terms of subtrees (how do we know we have the whole left subtree for a node; how do we know we have the whole right subtree), because you can no longer think about "setting" pointers, or tweaking them later.

This imperative piece was obtained to see if we can do the same in reverse.

Reply

ex_juan_gan July 25 2016, 00:27:16 UTC
Right. Just all my experience with mutable pointers tells me - it's a hell.

Reply

nponeccop July 25 2016, 03:38:34 UTC
Да даже удаление элемента из середины двунаправленного списка.

Reply


Leave a comment

Up