List of C ++ STL, stllist

Source: Internet
Author: User

List of C ++ STL, stllist

# Include <bits/stdc ++. h> using namespace std; int main () {// use the list container to process integer data list <int> l1; // declare it as the iterator list <int> :: iterator it; // previously added data l1.push _ front (2) to the l1 container; l1.push _ front (1 ); // Add data l1.push _ back (3) and l1.push _ back (4) to the l1 container ); // data 1 2 3 4 for (it = l1.begin (); it! = L1.end (); it ++) cout <* it <""; cout <endl; // display l1 data 4 3 2 1 list <int>: reverse_iterator ir; for (ir = l1.rbegin (); ir! = L1.rend (); ir ++) cout <* ir <""; cout <endl; // use STL accumulate (accumulate) algorithm int result = accumulate (l1.begin (), l1.end (), 0); // 0 is the initial value of cout <"Sum =" <result <endl; cout <"----------------" <endl; // -------------------------- // use the list container to process sorted data list <char> l2; // declare ir as the iterator list <char>: iterator itt; // Add data l2.push _ front ('B') to the l2 container '); l2.push _ front ('A'); // Add data from the back to the l2 container L2.push _ back ('C'); l2.push _ back ('D'); // displays data in l2 from the front to the back // a B C D for (itt = l2.begin (); itt! = L2.end (); itt ++) cout <* itt <""; cout <endl; // use The max_element algorithm of STL to calculate The maximum element in listTwo and display The following: itt = max_element (l2.begin (), l2.end (); cout <"The maximum element in l2 is: "<* itt <endl; cout <" ---------------- "<endl ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.