Usage of list in C + + STL

Source: Internet
Author: User

Blog move, http://t.cn/RvFZs2c. Usage of list in STL C + + Lists (linked list) Assign value (assign) Syntax:
  void assign (Input_iterator start, Input_iterator end);   

The Assign () function assigns a list to the range indicated by the iterator start and end or assigns a value of NUM to the list of elements with a Val value.

Related Topics: Insert (), Back Syntax:
  

The back () function returns a reference to the last element of the list.

Related Topics: Front (), Pop_back (), Begin Syntax:
  

The Begin () function returns an iterator that points to the first element of the list. For example

    Creating an element type is a list of characters     list<char> charList;     for (int i=0; i <; i++)       Charlist.push_front (i + +);      Show this list     list<char>::iterator theiterator;     for (Theiterator = Charlist.begin (); Theiterator! = Charlist.end (); theiterator++)       

Related Topics: end (), Clear Syntax:
  

The clear () function deletes all elements of the list.

Empty Syntax:
  

The empty () function returns True (TRUE) if the linked list is empty, otherwise false. For example:

    List<int> the_list;     for (int i = 0; i < i++)       the_list.push_back (i);       while (!the_list.empty ()) {       cout << the_list.front () << Endl;       The_list.pop_front ();     }           
End Syntax:
  

The end () function returns an iterator that points to the end of the list.

Related Topics: begin (), Erase Syntax:
  Iterator Erase (iterator POS);   

The erase () function deletes the element that indicates the position in POS, or removes the element between start and end . The return value is an iterator that points to the next element of the last deleted element.

Front Syntax:
  

The front () function returns a reference to the first element of the linked list.

    List<int> the_list;     for (int i = 0; i < i++)       the_list.push_back (i);       while (!the_list.empty ()) {       cout << the_list.front () << Endl;       The_list.pop_front ();     
Related Topics: Back (), Get_allocator Syntax:
  

The Get_allocator () function returns the list's configurator.

Insert Syntax:
  Iterator Insert (iterator pos, const TYPE &val);   void Insert (iterator pos, size_type num, const type &VAL);   

Insert () Inserts the element Val to position POS, or inserts the NUM element val before the POS, or inserts the start-to-end element into the POS position. The return value is an iterator that points to the element being inserted.

Max_size Syntax:
  

The Max_size () function returns the number of elements that a linked list can store.

Merge Syntax:
  void merge (list &lst);   

The merge () function connects itself to the LST list and produces a neatly arranged list of combinations. If Compfunction is specified, the specified function is used as the basis for comparison.

Pop_back Syntax:
  

The Pop_back () function deletes the last element of the linked list.

Related Topics: Pop_front (), Pop_front Syntax:
  

The Pop_front () function deletes the first element of a linked list.

Related Topics: pop_back (), Push_back Syntax:
  

Push_back () connects Val to the end of the linked list. For example:

    List<int> the_list;     for (int i = 0; i <; i++)       
Related Topics: Push_front (), Push_front Syntax:
  

The Push_front () function connects Val to the head of the linked list.

Related Topics: push_back (), Rbegin Syntax:
  

The Rbegin () function returns a reverse iterator that points to the end of the list.

Related Topics: rend (), Remove Syntax:
  

The Remove () function deletes all elements in the linked list that have a value of Val. For example

    Create a linked list of elements that are the first 10 elements of the alphabet     list<char> charList;     for (int i=0; i <; i++)       Charlist.push_front (i + +);      Delete all instances of ' E '     charlist.remove (' e ');   

Remove_if Syntax:
  

Remove_if () takes a unary predicate PR as the basis for judging elements, traversing the entire list. If the PR returns true, the element is deleted.

Rend Syntax:
  

The rend () function iterator points to the head of the linked list.

Resize Syntax:
  

The resize () function changes the size of the list to num. The extra elements that are added are assigned Val.

Reverse Syntax:
  

The reverse () function reverses all elements of the list.

Size Syntax:
  

The size () function returns the number of elements in the list.

Sorting (sort) Syntax:
  void sort ();   

The sort () function sorts the linked list, which is ascending by default. If Compfunction is specified, the specified function is used to determine the size of the two elements.

Splice Syntax:
  void Splice (iterator pos, list<t,allocator> &lst);   void Splice (iterator pos, list<t,allocator> &lst, iterator del);   

The splice () function connects the LST to the POS location. If other parameters are specified, insert the element from the Del in LST to the POS on the current list, or specify the range with start and end.

Swap Syntax:
  

The swap () function swaps the elements in the LST and the current list.

Unique Syntax:
  void Unique ();   

The unique () function deletes all duplicate elements in the linked list. If the PR is specified, the PR is used to determine whether to delete.

(go) Usage of list in C + + STL

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.