Deck 19: Standard Template Library

ملء الشاشة (f)
exit full mode
سؤال
You can assign stacks of the same base type
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Nonmodifying sequence algorithms do not change the elements in the containers they work on.
سؤال
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;.
سؤال
STL ranges [first,last)are always 'half-open' - from the first element to a designation for one past the last element.
سؤال
The operator * is prefixed to an iterator to insert an element in the container.
سؤال
The model for the iterator in the STL was the pointer.
سؤال
Order of magnitude estimates don't work well if we are interested in behavior for small data sets.
سؤال
The set container keeps track of how many copies of a data item you insert in the set object.
سؤال
The STL containers each define iterators appropriate to the internal structure of the container.
سؤال
The set container implements only iterator.
سؤال
Elements of a set and map are stored in sorted order.
سؤال
STL set operations are essentially insert,delete,and the query,"Is it there?".
سؤال
Insertion into a vector runtime is O(1)at any position in the vector.Explain what 'runtime is O(1)' means.
سؤال
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.
سؤال
The template stack and queue adapters have a copy constructor,an overloaded operator assignment,and a destructor.
سؤال
You cannot copy stacks.
سؤال
The Standard Template Library consists of the containers of various kinds.
سؤال
The associative containers store their data in an order different from the insertion order.
سؤال
Insertion into an STL list takes O(1)time at any position in the list.What does ' takes O(1)time' mean?
سؤال
Given a map m,the expression m["value"] will return NULL if there is no string named "value" stored in the map.
سؤال
What kind of iterators does the queue template container have?
سؤال
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.
سؤال
A failing find()operation on an STL set returns a null pointer value.
سؤال
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?
سؤال
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;
سؤال
If myVec has type vector what type does myVec.front()return?
سؤال
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.
سؤال
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.
سؤال
What is a generic algorithm?
سؤال
What kind of iterators does the stack template container have?
سؤال
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.
سؤال
Declare a stack template container to hold values of type double using the default container.
سؤال
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.
سؤال
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?
سؤال
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.
سؤال
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;
سؤال
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?
سؤال
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();
سؤال
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?
سؤال
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?
سؤال
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.
سؤال
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;
}
سؤال
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;
}
سؤال
Can you use the random_shuffle generic algorithm with a list container? What about a vector container? Why or why not?
سؤال
Why are the elements in the STL set (and map)kept sorted?
سؤال
What is different about mathematical sets and STL sets?
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/46
auto play flashcards
العب
simple tutorial
ملء الشاشة (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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
5
The operator * is prefixed to an iterator to insert an element in the container.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
6
The model for the iterator in the STL was the pointer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
7
Order of magnitude estimates don't work well if we are interested in behavior for small data sets.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
8
The set container keeps track of how many copies of a data item you insert in the set object.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
9
The STL containers each define iterators appropriate to the internal structure of the container.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
10
The set container implements only iterator.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
11
Elements of a set and map are stored in sorted order.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
12
STL set operations are essentially insert,delete,and the query,"Is it there?".
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
15
The template stack and queue adapters have a copy constructor,an overloaded operator assignment,and a destructor.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
16
You cannot copy stacks.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
17
The Standard Template Library consists of the containers of various kinds.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
18
The associative containers store their data in an order different from the insertion order.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
21
What kind of iterators does the queue template container have?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
23
A failing find()operation on an STL set returns a null pointer value.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
26
If myVec has type vector what type does myVec.front()return?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
29
What is a generic algorithm?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
30
What kind of iterators does the stack template container have?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
32
Declare a stack template container to hold values of type double using the default container.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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();
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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;
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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;
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
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?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
45
Why are the elements in the STL set (and map)kept sorted?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
46
What is different about mathematical sets and STL sets?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 46 في هذه المجموعة.