|
![](/i/fill.gif) |
On 9/5/2011 11:45, Warp wrote:
> Orchid XP v8<voi### [at] dev null> wrote:
>> insert :: Ord x => x -> MinHeap x -> MinHeap x
>> insert x' (Leaf ) = Node x' Leaf Leaf
>> insert x' (Node x h0 h1) = Node (min x x') (insert (max x x') h1) h0
>
> This is a good example of where it becomes confusing. Even after
> studying it for a few minutes I can't really figure out what is it
> that it's doing. (Or, more precisely *how* it's doing it. The 'insert'
> name makes it obvious what is it that it does, but the code doesn't make
> it at all clear how.)
I think part of it may be that you're thinking "insert" actually inserts
something in the heap. Nope! "insert" is a function that when given a value
and a heap, gives you back the new heap you would have were you to insert
that given value into that given heap.
--
Darren New, San Diego CA, USA (PST)
How come I never get only one kudo?
Post a reply to this message
|
![](/i/fill.gif) |