Data Structure-table (list)

Source: Internet
Author: User

#include <iostream>

#include <list>

using namespace Std;

Standard classes are stored in a two-way circular list

List class

1 classList2 {3 list ();4ListintNConstT&value=T ());5List (T *first,t *Last );6     //push_back ();7     //Pop_back ();8     //size ();9     //The above method is the same as the vector list also containsTen     voidPush_front (Constt&value); One     voidPop_front (); A       -Iterator begin ();//Iterators point to the first node by default -Iterator End ();//point to table header the      -     voidErase (iterator POS); -     voidErase (iterator first,iterator last);//Delete Interval -Iterator Insert (iterator POS,ConstT&value);//plug in front of POS +}

Iterator (STL Universal)

*iter; Value pointing to the node

iter++; Point to Next

iter--;

Iter1==iter2; Point to the same location

*iter1==*iter2; A value equal position is not necessarily

Instantiation:

Std::list<int>::iterator Iter=list.begin ();

Delete (! ):

List.erase (iter++); Note + + Otherwise the table after the delete node loses memory leaks

Here the + + operator overload first gets the next node position and then delete if ++iter then delete and get the next position

Insert Exercise:

void Doubledata (std::list <T> &alist)

{

Std::list<t>::iterator P=alist.begin ();

while (P!=alist.end ())

{

Alist.insert (P,*P);

p++;

}

}

Initial data: 1234 Output results: 11223344

Data Structure-table (list)

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.