Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > understanding merge sort

Reply
Thread Tools

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!


 
Reply With Quote
 
 
 
 
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.
 
Reply With Quote
 
 
 
 
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


 
Reply With Quote
 
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge Sort in C - array output is same as input after sort routine completes rkk C Programming 9 09-24-2006 08:30 PM
inputs for merge-sort vizziee@gmail.com VHDL 1 03-31-2005 12:35 PM
VHDL implementation of merge-sort vizziee@yahoo.com VHDL 2 01-04-2005 09:42 AM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM
Merge Sort question Seth G. Java 10 08-15-2003 12:02 AM



Advertisments