13.4. The Standard Template Library (STL)

Application (i.e., "real world") programs often manipulate large volumes of data. How the program organizes the data profoundly impacts program efficiency and effectiveness. A program's efficiency governs the data size that it can successfully handle. A program based on poorly organized data may work well with a dozen data items but prove completely unusable for two dozen.

For example, a past CS 1410 student wrote a program to count all the unique words in the book Alice In Wonderland (a book that he chose because it is now in the public domain and is available as a text file). His program used a linked list to hold each word and its count. Each time the program read a word from the file, it looked for the word in the list. It added the word if it wasn't in the list; otherwise, it incremented the count. His program ran for several minutes before completing the count. After the student replaced the list with a hash table (a data structure with a nearly-constant access time), the program finished in seconds. A binary tree will typically out-perform a list, but not a hash table. Computer scientists must know which data structure to use for a particular problem. The advantages and disadvantages of many well-known data structures are the primary topics of a "Data Structures and Algorithms" course.

Most general-purpose programming languages support some simple, primitive data structures. For example, C++ allows us to create arrays, structures, and classes. But providing direct language support for more complex data structures would result in an overly-complex compiler. The common approach is to provide libraries of various data structures. Java provides numerous collection classes in the util package. Java bases its collections on generic classes with a syntax that parallels C++ class templates. C++ also has a data structure library but bases the classes on templates and calls them containers.

C++ Standard Template Library (STL)

"A container is a holder object that stores a collection of other objects (its elements). They are implemented as class templates, which allows a great flexibility in the types supported as elements." The following links are excellent resources describing the STL.