Save
...
Done [Finals]
Computer Programming 2
List
Save
Share
Learn
Content
Leaderboard
Share
Learn
Created by
Marc
Visit profile
Cards (76)
What type of container is a list in STL?
A
sequential
container
View source
What memory allocation does a list allow?
Non-contiguous
memory allocation
View source
What data structure does a list implement?
Doubly linked list
View source
What is each element in a list called?
Node
View source
What is the structure of a node in a doubly linked list?
Previous Pointer
Data
Next Pointer
View source
What must be included in the header section to use a list?
#include
<list>
View source
How do you declare a list in C++?
list<dataType> listName;
View source
How do you create a list with initial values in C++?
list<
int
> num = {1, 2, 3, 4, 5};
list<
string
> names;
View source
What does the .front() function do in a list?
Returns the
first
element of a list
View source
What does the .back() function do in a list?
Returns the
last
element of a list
View source
What do iterators .begin() and .end() do in a list?
Access and traverse
the list content
View source
What does .begin() point to in a list?
First
element of the list
View source
What does .end() point to in a list?
Pointer after the
last
element
View source
What will cout << num.front(); display if num = {1, 2, 3, 4, 5}?
1
View source
What will cout << num.back(); display if num = {1, 2, 3, 4, 5}?
5
View source
How can you display all elements in a list using a range-based for loop?
for(int n : num)
View source
Why can't a STL list be accessed using index [] or .at() function?
It does not support
random access
View source
What is the purpose of the abs() function in the context of a list?
To get the
absolute value
of a number
View source
What does num.front() = -1; do to the list num = {1, 2, 3, 4, 5}?
Changes
first element to -1
View source
What does num.back() = -5; do to the list num = {1, 2, 3, 4, 5}?
Changes
last element to -5
View source
How do you add an element to the front of a list?
Using
.push_front()
View source
What does num.push_front(1); do?
Adds 1 to the front
of the list
View source
How do you add an element to the end of a list?
Using
.push_back()
View source
What does num.push_back(5); do?
Adds 5 to the end
of the list
View source
What is the purpose of the .insert() function?
Adds
multiple elements at different positions
View source
What is the syntax for the .insert() function?
listName.insert(position, value);
View source
What does num.insert(num.begin(), 0); do?
Adds 0 to the front
of the list
View source
What does num.insert(num.end(), 6); do?
Adds 6 to the end
of the list
View source
What does num.insert(pos, 3); do if pos points to element 4?
Adds 3 before element 4
View source
What does num.insert(pos, {3, 4}); do if pos points to element 6?
Adds 3 and 4 before element 6
View source
What does the .pop_front() function do?
Removes the first element
of a list
View source
What does num.pop_front(); do if num = {1, 2, 3, 4, 5}?
Removes the first element
View source
What does the .pop_back() function do?
Removes the last element
of a list
View source
What does num.pop_back(); do if num = {1, 2, 3, 4, 5}?
Removes the last element
View source
What is the purpose of the .erase() function?
Removes a
single element or range
of elements
View source
What is the syntax for the .erase() function?
listName.erase(position);
View source
What does num.erase(num.begin()); do?
Removes the first element
from the list
View source
What does num.erase(pos); do if pos points to the last element?
Removes the last element
from the
list
View source
What does num.erase(num.begin(), num.end()); do?
Removes all elements
from the list
View source
What are the key functions for modifying a list in STL?
.
push_front
() - Adds to front
.
push_back
() - Adds to end
.
insert
() - Adds at specific position
.
pop_front
() - Removes from front
.
pop_back
() - Removes from end
.
erase
() - Removes specific elements
View source
See all 76 cards