

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A series of code segments that need to be traced and output shown. The code segments involve the use of various STL containers such as list, deque, stack, set, and priority_queue. The purpose of the exercise is to test the student's understanding of the STL and their ability to trace code. The document also contains instructions not to use the computer, C++ compiler, or the internet for help with the exercises and to show scratchwork on the paper.
Typology: Exercises
1 / 3
This page cannot be seen from the preview
Don't miss anything!


designed by Matt V 2010
Trace the following code segments and show the output.
list
for (int j = 0; j < 6; j++) { numbers.insert(numbers.end(), k); k--; }
list
for (i = numbers.begin(); i != numbers.end(); i++) { cout << *i << endl; }
deque
for (int i = 1; i < 6; i++) { deqExample.push_front(k + 1); k++; }
deqExample.pop_front(); deqExample.pop_front();
for (int i = 0; i < deqExample.size(); ++i) { cout << deqExample[i] << ' '; }
stack
while (stackExample.size() != 0) { cout << stackExample.top() << " "; stackExample.pop();
set
for (i = setExample.begin(); i != setExample.end(); i++) cout << *i << " ";
list
for (int j = 0; j < 5; j++) { numbers.insert(numbers.end(), num); num++; }
numbers.pop_front(); numbers.reverse(); list
for (i = numbers.begin(); i != numbers.end(); i++) cout << *i << endl;
priority_queue
while (!pq.empty()) { cout << pq.top() << " "; pq.pop(); }
deque
for (int i = 1; i <= 6; i++)