Lecture 5 List

Source: Internet
Author: User

List container in STL

// Add, delete, search, and insert a string list # include "stdafx. H "# include <iostream> # include <string> # include <list> using namespace STD; int main () {list <string> olist; // List objects cannot be directly operated on. They can only be operated through algorithms or iterators. // olist [0] = "www.jiesoon.com "; // No // no reserved space for the list // olist. capacity (); // no such function // Add the olist element to the olist object. push_back ("3.jiesoon.com"); olist. push_front ("2.jiesoon.com"); olist. push_back ("4.jiesoon.com"); olist. push_front ("1. Jiesoon.com "); List <string >:: iterator itlist = olist. Begin (); For (; itlist! = Olist. end (); ++ itlist) {cout <* itlist <Endl;} cout <"olist existing elements:" <olist. size () <Endl; cout <"************************************ * ********* "<Endl; // list is a bidirectional linked list vector deque. You can also use the iterator to bidirectional access itlist = olist. begin (); // itlist + = 2; // No. List is not a continuous container + + itlist; ++ itlist; cout <* itlist <Endl; -- itlist; cout <* itlist <Endl; cout <"************************************ ********** "< <Endl; // insert data (unlike vector, deque inserts data in different locations with the same efficiency) itlist = olist. begin (); olist. insert (itlist, "0.jiesoon.com"); For (itlist = olist. begin (); itlist! = Olist. end (); ++ itlist) {cout <* itlist <Endl ;} cout <"************************************ * ********* "<Endl; // data deletion method ① olist. remove ("2.jiesoon.com"); For (itlist = olist. begin (); itlist! = Olist. end (); ++ itlist) {cout <* itlist <Endl ;} cout <"************************************ * ********* "<Endl; // data deletion method ② itlist = olist. begin (); olist. erase (itlist); For (itlist = olist. begin (); itlist! = Olist. End (); ++ itlist) {cout <* itlist <Endl;} return 0 ;}

 

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.