Intro to Data Structures


C++ has some built-in methods of storing compound data in useful ways, like arrays and structs.  There are other methods of storing data in unique ways that have useful applications in computer science.  These ideas are often grouped under the subject of Abstract Data Types, as they describe the nature of what is stored, along with the expected operations for accessing the data, without specifying the details of implementation.  In fact, there are often multiple ways to implement the same type of data structure.  C++ classes allow a nice mechanism for implementing such data types so that the interface (the public section) provides for the necessary operations, and the actual implementation details are internal and hidden.   The implementation of the class can be made to handle all of the storage details, along with any necessary dynamic allocation and cleanup.  Common data structures include:  stacks, queues, vectors, linked lists, trees, hash tables, sets, and others.  We will introduce a few of these concepts here.
 

Stacks

Queues

Vector

Linked List


Note: Some abstract types, like Stacks and Queues, can be implemented with a vector or with a linked list.  A stack can use a linked list as its underlying storage mechanism, for instance, but would limit the access to the list to just the "push" and "pop" concepts (insert and remove from one end).
 

Tree

Code Examples:

Examples from the textbook (Savitch)

Some code examples from Deitel (previously used textbook)

These examples are all implemented as class templates.