In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use list in C++". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use list in C++.
The use of structures
There are four main constructors, which are as follows
List () constructs empty listlist (size_type n, const value_type& val = value_type ()) the list contains n elements list (const list& x) with the value of val copy constructor list (InputIterator first, InputIterator last) constructs list1 to construct empty list with elements in [first, last) interval
Do not need to pass in any parameters, directly use the list class template to define the object
List L1; / define int linked list list L2; / define char linked list list L3; / / define val linked list / / three objects above, all empty 2 to construct elements with n values of char
You can pass parameters directly according to the above definition.
List L1 (4 list 5); / / defines an int linked list with 4 5 list L2 (3 recordings); / / defines a char linked list with 3's'L3 (4 list 3); / / defines an int linked list with 4 2.33 copy constructions
That is, pass in a list of the same type
List L1 (4 list 5); / / defines an int linked list containing 4 5 L2 (L1); / / makes a copy of L1 and gives it to L24 with iterative intervals
* * there is a note here, the iteration interval is left closed and right open! * * that does not include the right boundary.
Int num [4] = {1rec 2je 3je 4}; list L1 (3dhow`); list L2 (l1.begin (), l1.end ()); / / end () is the next element position of the last element position, so it does not include, so the content of L2 is' w`w' 'w'list L3 (num,num + 3). / / because of the location of num+3, the index is 3, but the iteration interval is left closed and right open, so the index 3 position is not included, and the content is 1 2 3 iterator interface.
C++ provides the following:
Function declaration interface description begin () + end () returns the iterator of the first element + iterator rbegin () + rend () returns the reverse_iterator of the next position of the last element, that is, the end position + returns the reverse_iterator of the next position of the last element, that is, the begin position 1 normal iterative interface int num [5] = {1, 2, 3, 4, 5}; list li (num,num+5) / / create a linked list with content 1 2 3 4 5 list::iterator it = li.begin (); while (it = li.end ()) {cout
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.