Question

In: Computer Science

Discuss tradeoffs between using the C++ STL list and vector.

Discuss tradeoffs between using the C++ STL list and vector.

Solutions

Expert Solution

STL stands for Standard Template Library. it is a library in the C++ language.

Actually, please use vector when you don't care about what type of sequential container that you're using, but if you're doing many insertions and from anywhere in the container other than the end, you should use list. if you require random access, then you have to use vector. You can find more about this in the below table...

vector C++ STL list
Elements are stored in Contiguous memory Non-contiguous memory
Pre-allocated memory, No pre-allocated memory
Each element only needs the space for the element type itself. Each element needs extra space for the node which holds the element
re-allocate memory for the entire vector any time that you add an element is possible. can't re-allocate memory
randomly access its elements. can't randomly access elements.
Iterators are disproving if you add or delete elements to or from the vector. Iterators remain valid even when you add or delete elements from the list.

PLEASE LIKE...THANK YOU!


Related Solutions

Language: C++ Conduct an evaluation of the performance of STL containers (vector, list, set, unordered_set) in...
Language: C++ Conduct an evaluation of the performance of STL containers (vector, list, set, unordered_set) in inserting and finding elements, with a relatively large data set. What you'll be measuring is the execution time. Obviously it's dependent on the speed of the computer one uses, so what matters is the relative speed (relative to the vector's speed in percentage) create a vector of 100,000 elements of integers, with the values initially set as 1~100,000, in this order. randomize the ordering...
Using only core C++ (no special libraries, except STL vector or string if you want), write...
Using only core C++ (no special libraries, except STL vector or string if you want), write a C++ program that allows a user to input a string and (a) Checks if the expression is a valid polynomial. Parentheses or negation are not allowed. Spaces should be ignored. E.g., the following are valid i. n^2+2*n+5 ii. 2*n + 4.54* n^5 +4 +5*n and the following are invalid iii. n^3n iv. n^4.2 v. 5n vi. n^3 -3*n if an input is given...
Conduct an evaluation of the performance of STL containers (vector, list, set, unordered_set) in inserting and...
Conduct an evaluation of the performance of STL containers (vector, list, set, unordered_set) in inserting and finding elements, with a relatively large data set. What you'll be measuring is the execution time. Obviously it's dependent on the speed of the computer one uses, so what matters is the relative speed (relative to the vector's speed in percentage) create a vector of 100,000 elements of integers, with the values initially set as 1~100,000, in this order. randomize the ordering of these...
STL vector C++ /* ---- OUTPUT ---- Enter test scores (-1 to quit) Enter a score:  77...
STL vector C++ /* ---- OUTPUT ---- Enter test scores (-1 to quit) Enter a score:  77 Enter a score:  83 Enter a score:  99 Enter a score:  67 Enter a score:  88 Enter a score:  -1 The average score is 82.8. Write a program in C++ that prompts the user to   Enter test scores (-1 to quit)    (see output) The program calculates and displays   the average of the test scores. Use a vector to hold the values double data type Pass the vector to a...
Verify using an example that vector a + (vector b * vector c) is not equal...
Verify using an example that vector a + (vector b * vector c) is not equal to (vector a + vector b) * (vector a + vector c) explain the problem that arrises
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet will be a simple class consisting of three fields: name: string representing the name of a planet, such as “Mars” madeOf: string representing the main element of the planet alienPopulation: int representing if the number of aliens living on the planet Your Planet class should have the following methods: Planet(name, madeOf, alienPopulation) // Constructor getName(): string // Returns a planet’s name getMadeOf(): String //...
Create a C++ program using native C++ (STL is acceptable) that produces Huffman code for a...
Create a C++ program using native C++ (STL is acceptable) that produces Huffman code for a string of text entered by the user. Must accept all ASCII characters. Provide an explanation for how you got frequencies of characters, how you sorted them, and how you got codes.
How to write a max-heap implementation of a templated priority queue class using the STL std::vector...
How to write a max-heap implementation of a templated priority queue class using the STL std::vector class to hold the data array
PROBLEM STATEMENT: Using the list container from the STL, write a program that will read the...
PROBLEM STATEMENT: Using the list container from the STL, write a program that will read the information from a file into a list and then display the list to the screen. Add your name. Sort the list by id. Print the list again CODE: Use the provided disneyin2.txt file. Do not hard code the file name; get file name from user. Use the struct below struct student { char firstnm[20], lastnm[20]; int id, grade; }; You are to create a...
In railroad industry, Describe the tradeoffs to be assessed between using a "broadly" or a "narrowly"...
In railroad industry, Describe the tradeoffs to be assessed between using a "broadly" or a "narrowly" graded ballast.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT