Hi Logan, When you say "Use SysQSort", you tried to say to me that I need to create the Quick Sort function or already exists the function of QuickSort to use. Thanks.
Edgar T. López ----- Original Message ----- From: "Logan Shaw" <[EMAIL PROTECTED]> To: "Palm Developer Forum" <[email protected]> Sent: Tuesday, May 24, 2005 12:58 PM Subject: Re: How to sort several databases? > Edgar T. López wrote: > > I have several databases, their names are formed by the date and the > > time of creation. For example: 19/5/05 4.44 pm, 6/5/05 4.24 pm. > > I already checked the DmGetNextDatabase function, but it said: > > "Because databases are scattered freely throughout memory space, > > they are not returned in any particular order—any database > > matching the specified type/creator criteria can be returned.". > > That is right. The Palm doesn't keep them in a sorted order, and > you can't make the Palm do it. > > > Thus,Do I need to create a function to sort my databases?, > > This depends on what you are trying to accomplish. If you want > to process them in order by date, you will need to sort them > yourself. If you need to just display a list of them, you could > put their names into an array and sort that. > > > If yes, > > Does anybody have any idea to do this?. > > If I needed to create a list of databases sorted by name (or in > some other order), I would use a procedure like this: > > (1) Count the number of databases that I care about. Either > iterate through all databases with something like this: > > UInt16 count = 0; > for (UInt16 index = 0; index < DmNumDatabases(); index++) > { > LocalID localid = DmGetDatabase (0, index); > if (DatabaseIsImportantToMe(localid)) > { > count++; > } > } > > Or, if you only want a certain type or creator, you can > use DmGetNextDatabaseByTypeCreator() to count them instead. > > (2) Use MemPtrNew() and create an array of LocalID values > of the appropriate size, based on the count. > > (3) Fill in LocalID values into the array with another loop > similar to that in step #1. > > (4) Use SysQSort() to sort the LocalID array, passing a pointer > to my own compare function. The compare function would use > the LocalID and DmDatabaseInfo() to get the information about > the database (such as name, modification date, whatever) > that you want to sort by. > > (5) Process everything in the LocalID array, then free the > array. > > Hope that helps. > > - Logan > > -- > For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/ > -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
