November 1999
Intermediate to advanced
336 pages
6h 29m
English
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); ...Read now
Unlock full access