In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the difference between vector and list in C++". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the difference between vector and list in C++".
A table allows you to understand the difference between vector and list vectorlist data structure: sequential table (dynamic array) ring two-way linked list physical space: continuous discontinuous memory consumption: less or more variable size: variable-dynamic array variable-random storage by pointer: support (vector overloaded []) does not support (because discontinuous) advantage: support random storage efficient insertion of any node, Operational disadvantages such as deletion: inserting and deleting to copy memory does not support random access
Comparison of data structures:
So how do we choose to use vector and list?
When choosing which data structure to use, you should follow this principle:
1. If you only care about random access and don't care about inserts and deletions, then consider vector
two。 If you only care about insertion and deletion, not random access, then consider list
Examples
When dealing with a large amount of data, the data is relatively fixed, do not care about sorting and intermediate value insertion and deletion, but select vector when querying and filtering.
When the order of the data is changed, the data changes, for example, the ranking list needs to be transposed, inserted and deleted, and select list.
Because of these differences between list and vector, there are some differences between list::iterator and vector::iterator. Take a look at the following example:
# include # include # include using namespace std; int main (void) {vector v; list l; for (int iTuno; I)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.