Special

Special Print Closeout!

We're clearing out the remainder of our print issues at fire sale prices -- as much as 75% off! Quantities are extremely limited and only available while supplies last. Hurry to take advantage of this one-time offer.

RBD Magazines

Once these printed back issues are gone, they are gone!

Article Preview


Buy Now

Print:
PDF:

Algorithms

Sorting Arrays 2

Bring Order To Your Objects

Issue: 5.3 (March/April 2007)
Author: Charles Yeomans
Article Description: No description available.
Article Length (in bytes): 8,866
Starting Page Number: 40
RBD Number: 5315
Resource File(s): None
Related Web Link(s):

http://www.declareSub.com/

Known Limitations: None

Excerpt of article text...

In the last issue, we began our discussion of sorting with a review of sorting capabilities built into REALbasic, and discussed insertion sort, a fundamental and simple sorting algorithm. In this column we look at merge sort.

Merge

Recall that the idea of insertion sort is the following. Given a sorted list of elements, it is simple to scan the list to decide where to insert a new element in sorted position to create a new sorted list. This is a special case of a more general problem: given two sorted lists, merge them to create a single sorted list containing the elements of both lists.

There is an obvious and simple algorithm for doing this. We compare the first elements of the two lists, and move the lesser of the two to the new list. Once one list is empty, we then move the remaining elements to the new list. This is quick algorithm, requiring only a comparison for each element of the smaller list.

It is also easy to implement. Here we do a straightforward implementation; there are also others that are not so straightforward.

...End of Excerpt. Please purchase the magazine to read the full article.

Article copyrighted by REALbasic Developer magazine. All rights reserved.


 


|

 


Weblog Commenting and Trackback by HaloScan.com