From SourceWiki
Revision as of 19:19, 13 April 2010 by GethinWilliams (talk | contribs) (→‎The C++ Standard Template Library)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

'Data Structures: starting to designing your program'


If your data structures effectively represent your area of modelling interest, the logic and control flow of your code will be naturally constrained and hence simpler and more robust to bugs.

svn co ./data-structures
less like this...
..and more like this.


cd examples/example1
  • The deliberately constrained nature of the stack gives elements a natural order.
  • Elements added early remain in the stack the longest.
A Stack.., in this case of boxes.

Linked Lists

cd ../example2
  • Can grow with more data
  • Can insert items in the middle of the list (e.g. can store items in order which arrive out of order)
A train--of knitted pigs--is much like a linked list.

Hash Tables

cd examples/example1
  • Content addressable storage.
  • Must manage potential collisions.
A hash table mapping names to phone numbers.




A quadtree could be used to store:

  • A sparse matrix (Can think of an image this way)
  • Variable resolution data (parent's value is the average of its children's values)

The C++ Standard Template Library

Pretty much rocks. And saves you the hassle of writing all these data structures yourself.