Five different kinds of "base" containers exist in JGL: maps, queues, sequences, sets, and stacks.
Each type of container has its own characteristics of access and element storage. For example, a queue implements a linked-list structure; a stack implements a first-in/last-out structure, and so on. (I'm using the "base" classes designation loosely. The map class is an abstract class, queue and stack are concrete classes, and sequence and set are interfaces. Think of them as the five main branches of the JGL container-class tree.)
But the container classes are only part of the JGL fabric. Algorithm classes provide the necessary mechanics for operations on containers. JGL includes algorithms for sorting, searching, counting, repl
acing, applying, and more. In addition, JGL defines a set of iterator classes for each container class so that you can easily program tight loops that process elements within a container.
But the real power of JGL is unleashed when containers, iterators, and algorithms are combined. The combination allows you to turn an algorithm loose on a container with just a few statements. For example, the following code shows how you might sort the first 10 elements of an array container:
ArrayIterator first =
array.begin();
ArrayIterator last =
array.begin();
last.advance(10);
Sorting.sort(first,last);
The
first
iterator is set to the front of the array. Then the
last
iterator is created and moved to just past the tenth element. Finally, the sort method is called to sort the subset of the array. Note that, with little modification, you could easily sort subsets
within
the array, as well as the entire array itself.