Friday, January 8, 2010

Chapter 4. C Data Structures



[ Team LiB ]






Chapter 4. C Data Structures



The ignoring of data is, in fact, the easiest and most popular mode of obtaining unity in one's thought.

�William James


Programs work by applying algorithms on data. The internal organization of data plays an important role in how algorithms operate.


You will find elements with the same type organized as a collection using a number of different mechanisms, each having different affordances regarding data storage and access. A vector, implemented as an array, offers random access to all elements, but it can be inefficient to change in size at runtime. A vector can also be used to organize groups of elements in the form of a table or stacked into two dimensions to create a matrix. Operations on a vector are sometimes restricted to occur at one end, in which case we talk about a stack, or in a first-in first-out order, treating the vector as a queue. When the order of the elements is not important, maps are used to create lookup tables and sets employed to form element collections.


The ability to link data elements together using pointers gives rise to a number of other structures you will often encounter. A linked list easily grows dynamically but offers only serial access (including stack and queue operations), whereas a suitably organized tree can be used to access data elements based on a key and can also easily grow dynamically while allowing traversal in an orderly fashion. We finish our discussion of C data structures with an examination of some applications and code patterns relating to graphs�the most flexible representation of linked data structures you will encounter.


Languages such as Java, C++, and C# offer abstractions for implementing these data structures as part of the language's library. In C these data structures are typically explicitly coded within the code body that uses them, however, their properties and the operations performed on them are common. The objective of this chapter is to learn how to read explicit data structure operations in terms of the underlying abstract data class.






    [ Team LiB ]



    No comments: