realbasic-nug
[Top] [All Lists]

Re: How do you sort Object arrays?

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: How do you sort Object arrays?
From: Fred of Occam <fred dot ofoccam at ntlworld dot com>
Date: Sat, 30 Sep 2006 13:47:21 +0000
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <20060930060602 dot 38D15153EDE4 at lists dot realsoftware dot com> <6F73476F-D62B-405A-8101-EE5D0852B543 at elfdata dot com>
The array of objects must itself be an object, or part of one.
Create a method of that object which performs a sort on the array, using some sorting key. Swap sort is the simplest, just comparing adjacent items and swapping them if required. It is of complexity N squared, so if your list is very long something like quick sort might be better.
Both of these need little extra memory.
If the object has any events, one of these could be used to call the sort when required. More likely you will have to call the sort externally whenever you read or write to the array of objects.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>