Deck 19: Standard Template Library

Full screen (f)
exit full mode
Question
You can assign stacks of the same base type
Use Space or
up arrow
down arrow
to flip the card.
Question
Nonmodifying sequence algorithms do not change the elements in the containers they work on.
Question
To declare an iterator,one must #include the proper header file,then specify the container type and use that with the scope resolution operator,::,to qualify the inner type iterator,to declare the iterator variable,as in
#include
std::vector::iterator myIterator;.
Question
STL ranges [first,last)are always 'half-open' - from the first element to a designation for one past the last element.
Question
The operator * is prefixed to an iterator to insert an element in the container.
Question
The model for the iterator in the STL was the pointer.
Question
Order of magnitude estimates don't work well if we are interested in behavior for small data sets.
Question
The set container keeps track of how many copies of a data item you insert in the set object.
Question
The STL containers each define iterators appropriate to the internal structure of the container.
Question
The set container implements only iterator.
Question
Elements of a set and map are stored in sorted order.
Question
STL set operations are essentially insert,delete,and the query,"Is it there?".
Question
Insertion into a vector runtime is O(1)at any position in the vector.Explain what 'runtime is O(1)' means.
Question
A Map is a function given as a set of ordered pairs.The first is the key that has to have ordering and the second is any type.The position of a pair in the set is determined by the ordering on the keys.
Question
The template stack and queue adapters have a copy constructor,an overloaded operator assignment,and a destructor.
Question
You cannot copy stacks.
Question
The Standard Template Library consists of the containers of various kinds.
Question
The associative containers store their data in an order different from the insertion order.
Question
Insertion into an STL list takes O(1)time at any position in the list.What does ' takes O(1)time' mean?
Question
Given a map m,the expression m["value"] will return NULL if there is no string named "value" stored in the map.
Question
What kind of iterators does the queue template container have?
Question
Assume proper includes have been executed,but not using directive or declaration.Write a definition of an iterator for a vector named vec of int values.Write a for loop that will display the contents vec on the screen,separated by spaces starting at the last element in the vector and proceeding to the first.Use iterators for the loop control.
Question
A failing find()operation on an STL set returns a null pointer value.
Question
I have an algorithm that runs in O(n2)time,where n is the size of the problem.What does "the size of the problem" mean?
Question
Why does the compiler complain if I attempt to use a vector as a base container for a stack of double values? The declaration is:
stack> myStack;
Question
If myVec has type vector what type does myVec.front()return?
Question
Assume proper includes have been executed,but no using directive or declaration.Write a definition of an iterator for a vector of ints that is initialized to point to the first member of the vector vec.
Question
Assume proper includes have been executed,but not using directive or declaration.Write a definition of an iterator for a vector named vec of int values.Write a for loop that will display the contents vec on the screen,separated by spaces.Use iterators for the loop control.
Question
What is a generic algorithm?
Question
What kind of iterators does the stack template container have?
Question
Define an iterator into a list of char of initial that allows traversal of the list for fetching from the list,but does not allow the list to be change through the iterator.Assume all includes and using directive/declarations have been executed.Assume further that the list has had sufficient elements inserted to support any actions needed.
Question
Declare a stack template container to hold values of type double using the default container.
Question
Declare a stack template container to hold values of type double using the list container.Write the necessary include and using statements.Mention any appropriate cautions about syntax.
Question
For a vector,inserting or deleting invalidates iterators in positions after the insertion or deletion.What happens to the set container if we delete in the middle?
Question
I have an algorithm that runs in O(N1/2),where n is the size of the problem.For N = 100,the time the algorithm runs is 1 minute.How long does the algorithm take for N=1000?
a)Same time
b)About 3 minutes
c)About 10 minutes
d)About 30 minutes
e)You haven't given enough information.I can't tell.
Question
Suppose you want to run code that involves the loop
//Assume vector v and iterator p has been defined and
//given appropriate values
for (p = v.begin();p != v.end();p++)
cout << *p << " ";
Which of the following could you use to declare the iterator p? Why?
std::vector::iterator p;
std::vector::const_iterator p;
Question
Suppose we are given an STL vector container named vec that holds values of type double.What do each of vec[0],vec.front(),*(vec.begin()),*(vec.end()- vec.size())and *(vec.rend()-1)mean?
Question
What is the difference between the iterators defined here.
vector vec;
//put 10 values into vec
const vector::iterator p = vec.begin();
vector::const_iterator q = vec.begin();
Question
I have an algorithm that runs in O(n2),where n is the size of the problem.What does "the size of the problem" mean?
Question
Suppose we are given an STL vector container named vec that holds values of type double.What do each of vec[vec.size()-1],vec.back(),*(vec.end()-1),*(vec.begin()+vec.size()-1)and *vec.rbegin()mean?
Question
Suppose you have a generic algorithm that requires forward iterators.Can I use it with a vector or a list even though these iterators are random access and bidirectional iterators respectively? Explain.
Question
Rewrite the code below using the ranged for loop and the auto keyword.
map personIDs = {
{1,"Walt"},
{2,"Kenrick"}
};
map::const_iterator iter;
for (iter = personIDs.begin();iter != personIDs.end();
iter++)
{
cout << iter->first << " " << iter->second << endl;
}
Question
The following code snippet is supposed to output "true" if the string "c++" is in the map and false otherwise.However,it has an error.Describe the error and give a fix.
if (mymap["c++"]==0)
{
cout << "false" << endl;
}
else
{
cout << "true" << endl;
}
Question
Can you use the random_shuffle generic algorithm with a list container? What about a vector container? Why or why not?
Question
Why are the elements in the STL set (and map)kept sorted?
Question
What is different about mathematical sets and STL sets?
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/46
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 19: Standard Template Library
1
You can assign stacks of the same base type
True
2
Nonmodifying sequence algorithms do not change the elements in the containers they work on.
True
3
To declare an iterator,one must #include the proper header file,then specify the container type and use that with the scope resolution operator,::,to qualify the inner type iterator,to declare the iterator variable,as in
#include
std::vector::iterator myIterator;.
True
4
STL ranges [first,last)are always 'half-open' - from the first element to a designation for one past the last element.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
5
The operator * is prefixed to an iterator to insert an element in the container.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
6
The model for the iterator in the STL was the pointer.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
7
Order of magnitude estimates don't work well if we are interested in behavior for small data sets.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
8
The set container keeps track of how many copies of a data item you insert in the set object.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
9
The STL containers each define iterators appropriate to the internal structure of the container.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
10
The set container implements only iterator.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
11
Elements of a set and map are stored in sorted order.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
12
STL set operations are essentially insert,delete,and the query,"Is it there?".
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
13
Insertion into a vector runtime is O(1)at any position in the vector.Explain what 'runtime is O(1)' means.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
14
A Map is a function given as a set of ordered pairs.The first is the key that has to have ordering and the second is any type.The position of a pair in the set is determined by the ordering on the keys.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
15
The template stack and queue adapters have a copy constructor,an overloaded operator assignment,and a destructor.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
16
You cannot copy stacks.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
17
The Standard Template Library consists of the containers of various kinds.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
18
The associative containers store their data in an order different from the insertion order.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
19
Insertion into an STL list takes O(1)time at any position in the list.What does ' takes O(1)time' mean?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
20
Given a map m,the expression m["value"] will return NULL if there is no string named "value" stored in the map.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
21
What kind of iterators does the queue template container have?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
22
Assume proper includes have been executed,but not using directive or declaration.Write a definition of an iterator for a vector named vec of int values.Write a for loop that will display the contents vec on the screen,separated by spaces starting at the last element in the vector and proceeding to the first.Use iterators for the loop control.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
23
A failing find()operation on an STL set returns a null pointer value.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
24
I have an algorithm that runs in O(n2)time,where n is the size of the problem.What does "the size of the problem" mean?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
25
Why does the compiler complain if I attempt to use a vector as a base container for a stack of double values? The declaration is:
stack> myStack;
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
26
If myVec has type vector what type does myVec.front()return?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
27
Assume proper includes have been executed,but no using directive or declaration.Write a definition of an iterator for a vector of ints that is initialized to point to the first member of the vector vec.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
28
Assume proper includes have been executed,but not using directive or declaration.Write a definition of an iterator for a vector named vec of int values.Write a for loop that will display the contents vec on the screen,separated by spaces.Use iterators for the loop control.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
29
What is a generic algorithm?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
30
What kind of iterators does the stack template container have?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
31
Define an iterator into a list of char of initial that allows traversal of the list for fetching from the list,but does not allow the list to be change through the iterator.Assume all includes and using directive/declarations have been executed.Assume further that the list has had sufficient elements inserted to support any actions needed.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
32
Declare a stack template container to hold values of type double using the default container.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
33
Declare a stack template container to hold values of type double using the list container.Write the necessary include and using statements.Mention any appropriate cautions about syntax.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
34
For a vector,inserting or deleting invalidates iterators in positions after the insertion or deletion.What happens to the set container if we delete in the middle?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
35
I have an algorithm that runs in O(N1/2),where n is the size of the problem.For N = 100,the time the algorithm runs is 1 minute.How long does the algorithm take for N=1000?
a)Same time
b)About 3 minutes
c)About 10 minutes
d)About 30 minutes
e)You haven't given enough information.I can't tell.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
36
Suppose you want to run code that involves the loop
//Assume vector v and iterator p has been defined and
//given appropriate values
for (p = v.begin();p != v.end();p++)
cout << *p << " ";
Which of the following could you use to declare the iterator p? Why?
std::vector::iterator p;
std::vector::const_iterator p;
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
37
Suppose we are given an STL vector container named vec that holds values of type double.What do each of vec[0],vec.front(),*(vec.begin()),*(vec.end()- vec.size())and *(vec.rend()-1)mean?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
38
What is the difference between the iterators defined here.
vector vec;
//put 10 values into vec
const vector::iterator p = vec.begin();
vector::const_iterator q = vec.begin();
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
39
I have an algorithm that runs in O(n2),where n is the size of the problem.What does "the size of the problem" mean?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
40
Suppose we are given an STL vector container named vec that holds values of type double.What do each of vec[vec.size()-1],vec.back(),*(vec.end()-1),*(vec.begin()+vec.size()-1)and *vec.rbegin()mean?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
41
Suppose you have a generic algorithm that requires forward iterators.Can I use it with a vector or a list even though these iterators are random access and bidirectional iterators respectively? Explain.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
42
Rewrite the code below using the ranged for loop and the auto keyword.
map personIDs = {
{1,"Walt"},
{2,"Kenrick"}
};
map::const_iterator iter;
for (iter = personIDs.begin();iter != personIDs.end();
iter++)
{
cout << iter->first << " " << iter->second << endl;
}
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
43
The following code snippet is supposed to output "true" if the string "c++" is in the map and false otherwise.However,it has an error.Describe the error and give a fix.
if (mymap["c++"]==0)
{
cout << "false" << endl;
}
else
{
cout << "true" << endl;
}
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
44
Can you use the random_shuffle generic algorithm with a list container? What about a vector container? Why or why not?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
45
Why are the elements in the STL set (and map)kept sorted?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
46
What is different about mathematical sets and STL sets?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 46 flashcards in this deck.