Sebastian Noack wrote:
Thanks for your reply. Now, I will use linked lists.
Do you now if there is a struct and some functions for
linked list? Or must I code it self?

Linked lists can be useful a lot of the time. But still, I think an array is better if you know in advance (before you start writing into it) how big it will be.

As far as I know, there are no linked list functions
built in.  You will have to do your own structure
and your own code too.  Most of the time, doing your
own code isn't too bad.  The one situation that does
present a problem is that there is no function to sort
a linked list, and writing your own function to sort
a linked list efficiently can be a real pain.

Once or twice I've run into that situation, and my
solution was to write a loop to count the nodes,
then allocate an array based on the node count,
then put a pointer to each node into an array element.
Then you can use SysQSort() to sort the nodes, and
then reconstruct the list in the right order.  (Or,
in some cases, it's more convenient to just use the
sorted pointers in the array and then throw away the
array when you're done with it, leaving the linked
list just as it was before.)

Another option is to create your own dynamically-sized
list data structure.  One simple way of doing this is to
use an array and double its size every time someone tries
to write off the end of the array.  You have to copy the
array every time you double it (unless you luck out and
MemPtrResize() can resize it for you), but that cost is
usually amortized over accessing all the elements in the
list, so it's actually only O (log n) or better if you
access every element of the list at least once.

Then another option is to create a linked list of arrays.
The first array holds the first element of your list, the
second holds the next 2, the third the next 4, the fourth
the next 8, etc.  This avoids the copying, but you do have
to traverse the linked list of arrays every time you access
an element of your list.  Still, it's not so bad since
the size of the linked list is the logarithm of the number
of items you put in your list.

  - Logan

To unsubscribe send an email to  [EMAIL PROTECTED]
--
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to