Velocity Reviews > Ruby > understanding merge sort

# understanding merge sort

josh
Guest
Posts: n/a

 12-17-2011
Here is the code (including the test).
http://pastebin.com/QH46wghT

it's working but i don't understand why this line:
merge_sort(a2)
works. I would think of doing this: a2 = merge_sort(a2) since i don't
see where are we assigning the return value of merge_sort into a2.

I guess there is something with recursion that I completely miss...
Thanks!

sreservoir
Guest
Posts: n/a

 12-17-2011
On 12/16/2011 11:19 PM, josh wrote:
> Here is the code (including the test).
> http://pastebin.com/QH46wghT
>
> it's working but i don't understand why this line:
> merge_sort(a2)
> works. I would think of doing this: a2 = merge_sort(a2) since i don't
> see where are we assigning the return value of merge_sort into a2.
>
> I guess there is something with recursion that I completely miss...
> Thanks!

it's an in-place sort.

David Combs
Guest
Posts: n/a

 01-22-2012
In article <jcigjr\$4vm\$(E-Mail Removed)>,
sreservoir <(E-Mail Removed)> wrote:
>On 12/16/2011 11:19 PM, josh wrote:
>> Here is the code (including the test).
>> http://pastebin.com/QH46wghT
>>
>> it's working but i don't understand why this line:
>> merge_sort(a2)
>> works. I would think of doing this: a2 = merge_sort(a2) since i don't
>> see where are we assigning the return value of merge_sort into a2.
>>
>> I guess there is something with recursion that I completely miss...
>> Thanks!

>
>it's an in-place sort.

Maybe check out wikipedia, via googling merge sort.

David

Robert Klemme
Guest
Posts: n/a

 01-22-2012
On 22.01.2012 03:37, David Combs wrote:
> In article<jcigjr\$4vm\$(E-Mail Removed)>,
> sreservoir<(E-Mail Removed)> wrote:
>> On 12/16/2011 11:19 PM, josh wrote:
>>> Here is the code (including the test).
>>> http://pastebin.com/QH46wghT
>>>
>>> it's working but i don't understand why this line:
>>> merge_sort(a2)
>>> works. I would think of doing this: a2 = merge_sort(a2) since i don't
>>> see where are we assigning the return value of merge_sort into a2.
>>>
>>> I guess there is something with recursion that I completely miss...
>>> Thanks!

>>
>> it's an in-place sort.

>
> Maybe check out wikipedia, via googling merge sort.

Wikipedia is a good source. But I think a good book about algorithms
and data structures (e.g. Sedgewick) should be on anyone's shelve who is
doing programming.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/