![](https://seccdn.libravatar.org/avatar/0d0434a1c7ca43ef1a88fee5ecda1edf.jpg?s=120&d=mm&r=g)
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Boyd Stephen Smith Jr. wrote:
In <1259192047.12762.6.camel@manta.site>, Roger Oberholtzer wrote:
There are many discussions of manipulating double linked lists. The basic idea is you allocate the addition, and store it either as next or previous. There are details to watch. But google is your friend.
The OP wanted a 2D array, not a 1D list structure.
If you want a 2D list structure, you'll need "up" and "down" pointers similar to the "next" (or "right") and "prev" (or "left") pointers. If you have to do insertions in the middle, or at both ends of the structure, this will likely serve you best. It may also be good even if insertions only happen at one end of the structure.
You probably don't want a 2D array, since that implies compact storage of elements which would require the majority of the array to be copied when expanding one of the dimensions. (In addition to any copies required because no more memory can be contiguously allocated.) [You may need this compact storage model, but it's unlikely.]
If you only need to do insertions are one end, an array of (pointers to) arrays would also be a good solution.
A sparse array implemented as a double linked list of double linked lists might fit, and abstracting the array handling function from the underlying data structures may help readability and improve the ability to define error and array handling functions. The following pseudo-code gives an outline of a possible data structure implementation.... typedef struct { int yIndex; struct data *data; struct yData *next,*previous; } yData; typedef struct { int xIndex; struct yData *yData; struct xData *next,*previous; } xData; where data is your data structure.... The existence and the type of the index field depends a bit on array indexing requirements and it should be noted that random retrieval performance may be very poor with large amounts of data. But this can be very memory efficient if the data objects are thinly spread out within the index space.
The tip and caveat I snipped are valuable, but need not be repeated any more than I already have. In addition, however you do things, make sure to initialize stuff ASAP after you have allocated it. Uninitialized pointers are a mess to debug manually, although valgrind can help a lot.
- -- ============================================================================== I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone. Bjarne Stroustrup ============================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iEYEARECAAYFAksOVDEACgkQasN0sSnLmgKA6gCfQP9rIHq+C9L/ltOX7GeU4ycL Xc4AnjG5UfDUTwDsHegidsf/x0L2B18Z =vaMv -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org