## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

### Traversal

We often need to traverse a container one element at a time, performing a computation on each element. We picked the STL's accumulate() function to represent container traversal. The accumulate() function traverses the container from beginning to end, adding all elements in the process. The containers under test were an array, vector, and list. Each container stored an identical collection of 10,000 random integers. The test code for the various containers is as follows:

` void vectorTraverse (vector<int> *v, int size) { int sum = accumulate(v->begin(), v->end(),0); } void arrayTraverse (int *a, int size) { int sum = accumulate(&a[0], &a[size],0); } void listTraverse (list<int> *l, int size) { int sum = accumulate(l->begin(), l->end(),0); ...`

## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required