Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objectives: Gain familiarity with the STL by adding and removing items from STL

ID: 3597607 • Letter: O

Question

Objectives: Gain familiarity with the STL by adding and removing items from STL containers; compare performance of adding and removing items from containers.

#include <time.h>

clock_t timerStart, timerEnd;

timerStart = clock();

// place code you want to time here

timerEnd = clock();

// Elapsed time in milliseconds is timerEnd – timerStart – Convert all answers to decimal seconds (e.g., 0.124 secs).

In Visual Studio 2015, declare the following STL containers:

a vector that holds ints – add items using push_back()

a list that holds ints – add items using push_front()

a forward_list that holds ints – add items using push_front()

a stack (with the default deque implementation) that holds ints

a stack (implemented as a vector) that holds ints

a stack (implemented as a list) that holds ints

a queue (with the default queue implementation) that holds ints – add with push(), remove with pop()

a queue (implemented as a deque) that holds ints – add with push_back, remove with pop_front()

a queue (implemented as a list) that holds ints – add with push(), remove with pop()

Explanation / Answer

and you’d like to redraw all the Widgets in a list, you could do it with a loop, like this,

but you could also do it with the for_each algorithm: