当前位置: 首页 > news >正文

wordpress商务版插件苏州关键词优化软件

wordpress商务版插件,苏州关键词优化软件,成都建模培训,爱站网做网站吗前言 本篇博客我们继续来介绍STL的内容,这次我们要介绍的是list这个容器,可以简单地理解为顺序表,当然和我们之前学过顺序表还是有区别的,具体内容大家可以继续往下阅读,下面进入正文。 1. list简介 1.list是一种可…

前言

本篇博客我们继续来介绍STL的内容,这次我们要介绍的是list这个容器,可以简单地理解为顺序表,当然和我们之前学过顺序表还是有区别的,具体内容大家可以继续往下阅读,下面进入正文。

1. list简介

1.list是一种可以在常数范围内在任意位置进行插入和删除的序列式容器,并且该容器可以前后双向迭代。
2.list的底层是双向链表结构,双向链表中每个元素存储在互不相关的独立结点当中,在结点中通过指针指向其前一个元素和后一个元素。
3,list与forward_list非常相似,最主要的不同在于forward_list是单链表,只能进行单方向迭代。
与其他容器相比,list通常在任意位置进行插入、删除元素的执行效率更高。
4.list和forward_list最大的缺陷是不支持在任意位置的随机访问,其次,list还需要一些额外的空间,以保存每个结点之间的关联信息(对于存储的类型较小元素来说这可能是一个重要的因素)。

2. list的使用

2.1 list的定义方式

2.1.1 构造一个某类型的空容器

list<int> lt1; //构造int类型的空容器

2.1.2  构造一个含有n个val的某类型容器

list<int> lt2(10, 2); //构造含有10个2的int类型容器

2.1.3 拷贝构造某类型容器的复制品

list<int> lt3(lt2); //拷贝构造int类型的lt2容器的复制品

2.1.4 使用迭代器拷贝构造某一段内容

string s("hello world");
list<char> lt4(s.begin(),s.end()); //构造string对象某段区间的复制品

2.1.5 构造数组某段区间的复制品

int arr[] = { 1, 2, 3, 4, 5 };
int sz = sizeof(arr) / sizeof(int);
list<int> lt5(arr, arr + sz); //构造数组某段区间的复制品

2.2 list的插入和删除

2.2.1 push_front和pop_front

push_front函数用于头插一个数据,pop_front函数用于头删一个数据。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt;lt.push_front(0);lt.push_front(1);lt.push_front(2);for (auto e : lt){cout << e << " ";}cout << endl; //2 1 0lt.pop_front();for (auto e : lt){cout << e << " ";}cout << endl; //1 0return 0;
}

2 1 0
1 0

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 21668)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.2.2 push_back和pop_back

push_back函数用于尾插一个数据,pop_back函数用于尾删一个数据。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt;lt.push_back(0);lt.push_back(1);lt.push_back(2);lt.push_back(3);for (auto e : lt){cout << e << " ";}cout << endl; //0 1 2 3lt.pop_back();lt.pop_back();for (auto e : lt){cout << e << " ";}cout << endl;//0 1return 0;
}

0 1 2 3
0 1

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 15064)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.2.3 insert

list当中的insert函数支持三种插入方式:

  1. 在指定迭代器位置插入一个数。
  2. 在指定迭代器位置插入n个值为val的数。
  3. 在指定迭代器位置插入一段迭代器区间(左闭右开)。
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;int main()
{list<int> lt;lt.push_back(1);lt.push_back(2);lt.push_back(3);list<int>::iterator pos = find(lt.begin(), lt.end(), 2);lt.insert(pos, 9); //在2的位置插入9for (auto e : lt){cout << e << " ";}cout << endl; //1 9 2 3pos = find(lt.begin(), lt.end(), 3);lt.insert(pos, 2, 8); //在3的位置插入2个8for (auto e : lt){cout << e << " ";}cout << endl; //1 9 2 8 8 3vector<int> v(2, 7);pos = find(lt.begin(), lt.end(), 1);lt.insert(pos, v.begin(), v.end()); //在1的位置插入2个7for (auto e : lt){cout << e << " ";}cout << endl; //7 7 1 9 2 8 8 3return 0;
}

1 9 2 3
1 9 2 8 8 3
7 7 1 9 2 8 8 3

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 34536)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

注: find函数是头文件“algorithm”当中的一个函数,该函数在指定迭代器区间寻找指定值的位置,并返回该位置的迭代器。

2.2.4 erase

list当中的erase函数支持两种删除方式:

  1. 删除指定迭代器位置的元素。
  2. 删除指定迭代器区间(左闭右开)的所有元素。
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;int main()
{list<int> lt;lt.push_back(1);lt.push_back(2);lt.push_back(3);lt.push_back(4);lt.push_back(5);list<int>::iterator pos = find(lt.begin(), lt.end(), 2);lt.erase(pos); //删除2for (auto e : lt){cout << e << " ";}cout << endl; //1 3 4 5pos = find(lt.begin(), lt.end(), 4);lt.erase(pos, lt.end()); //删除4及其之后的元素for (auto e : lt){cout << e << " ";}cout << endl; //1 3return 0;
}

1 3 4 5
1 3

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 26072)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.3 迭代器的使用

2.3.1 begin和end

通过begin函数可以得到容器中第一个元素的正向迭代器,通过end函数可以得到容器中最后一个元素的后一个位置的正向迭代器。

正向迭代器遍历容器:

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt(10, 2);//正向迭代器遍历容器list<int>::iterator it = lt.begin();while (it != lt.end()){cout << *it << " ";it++;}cout << endl;return 0;
}

2 2 2 2 2 2 2 2 2 2

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 27264)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

这里大家可以发现,和前面基本一模一样的,就换了一下容器,所以STL这里的学习是有相通性的,掌握了一个,剩下的都比较相似。

2.3.2 rbegin和rend

通过rbegin函数可以得到容器中最后一个元素的反向迭代器,通过rend函数可以得到容器中第一个元素的前一个位置的反向迭代器。

反向迭代器遍历容器:

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt(10, 2);//反向迭代器遍历容器list<int>::reverse_iterator rit = lt.rbegin();while (rit != lt.rend()){cout << *rit << " ";rit++;}cout << endl;return 0;
}

2 2 2 2 2 2 2 2 2 2

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 29276)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.4 list的元素获取

2.4.1 front和back

front函数用于获取list容器当中的第一个元素,back函数用于获取list容器当中的最后一个元素。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt;lt.push_back(0);lt.push_back(1);lt.push_back(2);lt.push_back(3);lt.push_back(4);cout << lt.front() << endl; //0cout << lt.back() << endl; //4return 0;
}

0
4

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 22184)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.5 list的大小控制

2.5.1 size

size函数用于获取当前容器当中的元素个数。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt;lt.push_back(1);lt.push_back(2);lt.push_back(3);lt.push_back(4);cout << lt.size() << endl; //4return 0;
}

4

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 33192)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.5.2 resize

resize的两种情况:

  1. 当所给值大于当前的size时,将size扩大到该值,扩大的数据为第二个所给值,若未给出,则默认为容器所存储类型的默认构造函数所构造出来的值。
  2. 当所给值小于当前的size时,将size缩小到该值
#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt(5, 3);for (auto e : lt){cout << e << " ";}cout << endl; //3 3 3 3 3lt.resize(7, 6); //将size扩大为7,扩大的值为6for (auto e : lt){cout << e << " ";}cout << endl; //3 3 3 3 3 6 6lt.resize(2); //将size缩小为2for (auto e : lt){cout << e << " ";}cout << endl; //3 3return 0;
}

3 3 3 3 3
3 3 3 3 3 6 6
3 3

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 20692)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

 

2.5.3 empty

empty函数用于判断当前容器是否为空。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt;cout << lt.empty() << endl; //1return 0;
}

1

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 30808)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.5.4 clear

clear函数用于清空容器,清空后容器的size为0。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt(5, 2);for (auto e : lt){cout << e << " ";}cout << endl; //2 2 2 2 2cout << lt.size() << endl; //5lt.clear(); //清空容器for (auto e : lt){cout << e << " ";}cout << endl; //(无数据)cout << lt.size() << endl; //0return 0;
}

2 2 2 2 2
5

0

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 33584)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.6 list的操作函数

2.6.1 sort

sort函数可以将容器当中的数据默认排为升序。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt;lt.push_back(4);lt.push_back(7);lt.push_back(5);lt.push_back(9);lt.push_back(6);lt.push_back(0);lt.push_back(3);for (auto e : lt){cout << e << " ";}cout << endl; //4 7 5 9 6 0 3lt.sort(); //默认将容器内数据排为升序for (auto e : lt){cout << e << " ";}cout << endl; //0 3 4 5 6 7 9return 0;
}

4 7 5 9 6 0 3
0 3 4 5 6 7 9

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 31372)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.6.2 splice

splice函数用于两个list容器之间的拼接,其有三种拼接方式:

  1. 将整个容器拼接到另一个容器的指定迭代器位置。
  2. 将容器当中的某一个数据拼接到另一个容器的指定迭代器位置。
  3. 将容器指定迭代器区间的数据拼接到另一个容器的指定迭代器位置。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt1(4, 2);list<int> lt2(4, 6);lt1.splice(lt1.begin(), lt2); //将容器lt2拼接到容器lt1的开头for (auto e : lt1){cout << e << " ";}cout << endl; //6 6 6 6 2 2 2 2 list<int> lt3(4, 2);list<int> lt4(4, 6);lt3.splice(lt3.begin(), lt4, lt4.begin()); //将容器lt4的第一个数据拼接到容器lt3的开头for (auto e : lt3){cout << e << " ";}cout << endl; //6 2 2 2 2 list<int> lt5(4, 2);list<int> lt6(4, 6);lt5.splice(lt5.begin(), lt6, lt6.begin(), lt6.end()); //将容器lt6的指定迭代器区间内的数据拼接到容器lt5的开头for (auto e : lt5){cout << e << " ";}cout << endl; //6 6 6 6 2 2 2 2return 0;
}

6 6 6 6 2 2 2 2
6 2 2 2 2
6 6 6 6 2 2 2 2

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 3556)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

注意: 容器当中被拼接到另一个容器的数据在原容器当中就不存在了。(实际上就是将链表当中的指定结点拼接到了另一个容器当中)

2.6.3 remove

remove函数用于删除容器当中特定值的元素。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt;lt.push_back(1);lt.push_back(4);lt.push_back(3);lt.push_back(3);lt.push_back(2);lt.push_back(2);lt.push_back(3);for (auto e : lt){cout << e << " ";}cout << endl; //1 4 3 3 2 2 3lt.remove(3); //删除容器当中值为3的元素for (auto e : lt){cout << e << " ";}cout << endl; //1 4 2 2return 0;
}

1 4 3 3 2 2 3
1 4 2 2

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 25988)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.6.4 remove_if

remove_if函数用于删除容器当中满足条件的元素。

#include <iostream>
#include <list>
using namespace std;bool single_digit(const int& val)
{return val < 10;
}
int main()
{list<int> lt;lt.push_back(10);lt.push_back(4);lt.push_back(7);lt.push_back(18);lt.push_back(2);lt.push_back(5);lt.push_back(9);for (auto e : lt){cout << e << " ";}cout << endl; //10 4 7 18 2 5 9lt.remove_if(single_digit); //删除容器当中值小于10的元素for (auto e : lt){cout << e << " ";}cout << endl; //10 18return 0;
}

10 4 7 18 2 5 9
10 18

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 27772)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.6.5 unique

unique函数用于删除容器当中连续的重复元素。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt;lt.push_back(1);lt.push_back(4);lt.push_back(3);lt.push_back(3);lt.push_back(2);lt.push_back(2);lt.push_back(3);for (auto e : lt){cout << e << " ";}cout << endl; //1 4 3 3 2 2 3lt.sort(); //将容器当中的元素排为升序lt.unique(); //删除容器当中连续的重复元素for (auto e : lt){cout << e << " ";}cout << endl; //1 2 3 4return 0;
}

1 4 3 3 2 2 3
1 2 3 4

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 30556)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.6.6 merge

merge函数用于将一个有序list容器合并到另一个有序list容器当中,使得合并后的list容器仍然有序。(类似于归并排序)

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt1;lt1.push_back(3);lt1.push_back(8);lt1.push_back(1);list<int> lt2;lt2.push_back(6);lt2.push_back(2);lt2.push_back(9);lt2.push_back(5);lt1.sort(); //将容器lt1排为升序lt2.sort(); //将容器lt2排为升序lt1.merge(lt2); //将lt2合并到lt1当中for (auto e : lt1){cout << e << " ";}cout << endl; //1 2 3 5 6 8 9 return 0;
}

1 2 3 5 6 8 9

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 4632)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.6.7 reverse

reverse函数用于将容器当中元素的位置进行逆置。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt;lt.push_back(1);lt.push_back(2);lt.push_back(3);lt.push_back(4);lt.push_back(5);lt.reverse(); //将容器当中元素的位置进行逆置for (auto e : lt){cout << e << " ";}cout << endl; //5 4 3 2 1 return 0;
}

5 4 3 2 1

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 33212)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.6.8 assign

assign函数用于将新内容分配给容器,替换其当前内容,新内容的赋予方式有两种:

  1. 将n个值为val的数据分配给容器。
  2. 将所给迭代器区间当中的内容分配给容器。
#include <iostream>
#include <string>
#include <list>
using namespace std;int main()
{list<char> lt(3, 'a');lt.assign(3, 'b'); //将新内容分配给容器,替换其当前内容for (auto e : lt){cout << e << " ";}cout << endl; //b b bstring s("hello world");lt.assign(s.begin(), s.end()); //将新内容分配给容器,替换其当前内容for (auto e : lt){cout << e << " ";}cout << endl; //h e l l o   w o r l dreturn 0;
}

b b b
h e l l o   w o r l d

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 33432)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

2.6.9 swap

swap函数用于交换两个容器的内容。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> lt1(4, 2);list<int> lt2(4, 6);lt1.swap(lt2); //交换两个容器的内容for (auto e : lt1){cout << e << " ";}cout << endl; //6 6 6 6for (auto e : lt2){cout << e << " ";}cout << endl; //2 2 2 2return 0;
}

6 6 6 6
2 2 2 2

C:\code\test_c\test_10_30\x64\Debug\test_10_30.exe (进程 22184)已退出,代码为 0 (0x0)。
按任意键关闭此窗口. . .

3. 总结

本篇博客为大家介绍了list这个容器,提到了它与其他容器相似的用法;还介绍了list特有的一些用法,大家需要重点掌握我上面所提到的接口,注意它们的联系与区别,以及每个接口所具有的细节,最后,希望本篇博客可以为大家带来帮助,感谢阅读!


文章转载自:
http://lipophilic.c7617.cn
http://stylopodium.c7617.cn
http://catenation.c7617.cn
http://versant.c7617.cn
http://flack.c7617.cn
http://matriarchy.c7617.cn
http://kestrel.c7617.cn
http://kanu.c7617.cn
http://puket.c7617.cn
http://lorn.c7617.cn
http://longstop.c7617.cn
http://mixtecan.c7617.cn
http://fzs.c7617.cn
http://apulia.c7617.cn
http://erebus.c7617.cn
http://palaeanthropic.c7617.cn
http://extractive.c7617.cn
http://purim.c7617.cn
http://shirk.c7617.cn
http://airfield.c7617.cn
http://rayl.c7617.cn
http://shearwater.c7617.cn
http://dystocia.c7617.cn
http://vacuometer.c7617.cn
http://hesitant.c7617.cn
http://paranephros.c7617.cn
http://externality.c7617.cn
http://phenicia.c7617.cn
http://drysaltery.c7617.cn
http://matting.c7617.cn
http://carretela.c7617.cn
http://dogfish.c7617.cn
http://categorical.c7617.cn
http://bumblepuppy.c7617.cn
http://noctuid.c7617.cn
http://kate.c7617.cn
http://foolhardiness.c7617.cn
http://yenan.c7617.cn
http://nfu.c7617.cn
http://noisome.c7617.cn
http://bromelia.c7617.cn
http://incus.c7617.cn
http://micropublishing.c7617.cn
http://synclastic.c7617.cn
http://adenocarcinoma.c7617.cn
http://burnisher.c7617.cn
http://separably.c7617.cn
http://podzolisation.c7617.cn
http://switchover.c7617.cn
http://scintiscan.c7617.cn
http://teachy.c7617.cn
http://hack.c7617.cn
http://fund.c7617.cn
http://backdrop.c7617.cn
http://pontic.c7617.cn
http://luftwaffe.c7617.cn
http://grossly.c7617.cn
http://ventilate.c7617.cn
http://piles.c7617.cn
http://mulch.c7617.cn
http://labefaction.c7617.cn
http://sheridan.c7617.cn
http://weakfish.c7617.cn
http://multimillionaire.c7617.cn
http://altiplano.c7617.cn
http://magnetostatic.c7617.cn
http://suppository.c7617.cn
http://kaif.c7617.cn
http://poetry.c7617.cn
http://british.c7617.cn
http://chemoprophylactic.c7617.cn
http://urologist.c7617.cn
http://autocoder.c7617.cn
http://inconvenience.c7617.cn
http://yami.c7617.cn
http://untrodden.c7617.cn
http://bergschrund.c7617.cn
http://horsebreaker.c7617.cn
http://foliaceous.c7617.cn
http://floral.c7617.cn
http://pratincole.c7617.cn
http://moxibustion.c7617.cn
http://recti.c7617.cn
http://rookery.c7617.cn
http://pseudocyesis.c7617.cn
http://hansa.c7617.cn
http://politic.c7617.cn
http://rubberwear.c7617.cn
http://malayan.c7617.cn
http://unmentionable.c7617.cn
http://czech.c7617.cn
http://hegemonism.c7617.cn
http://ideation.c7617.cn
http://squaresville.c7617.cn
http://editola.c7617.cn
http://paleogeophysics.c7617.cn
http://sgram.c7617.cn
http://nipponese.c7617.cn
http://potheen.c7617.cn
http://aeroengine.c7617.cn
http://www.zhongyajixie.com/news/72658.html

相关文章:

  • node.js做网站好累开发一个网站需要哪些技术
  • 网站模板带后台 下载企业网站制作开发
  • 国内免费图片素材网站百度app大全
  • 昆山做网站费用站外推广怎么做
  • 做企业网站需要服务器么发广告平台有哪些
  • 陕西省城乡住房建设部网站网站推广找
  • 学做巧裁缝官方网站好用的视频播放器app
  • 中国建设银行启东市支行网站百度注册公司网站
  • 建一个网站 服务器机房托管价格什么网站可以发布广告
  • 沈阳建站模板系统包括百度收录网址提交
  • 营销型网站建设标准黄冈网站搭建推荐
  • 网站建设专业知识ks刷粉网站推广马上刷
  • 如何修改wordpress首页系统优化的意义
  • 如何做b2b网站东莞网站营销策划
  • 好男人社区辽宁网站seo
  • 做微网站自己的产品怎么推广
  • 赵县网站建设重庆seo推广
  • 房地产最新政策谷歌seo搜索优化
  • 大气物流网站源码2021最近比较火的营销事件
  • 道真县住房和城乡建设局网站数据分析师需要学哪些课程
  • wordpress 所有文章快速优化网站排名软件
  • 北京上海网站建设搜索seo是什么意思
  • 江西省工程建设网站网站收录软件
  • ueeshop外贸建站公司我是新手如何做电商
  • wordpress主题知更上海网络公司seo
  • 用java怎么做网站流量大的推广平台有哪些
  • 怎么做仲博注册网站广告推广赚钱在哪接
  • 百度抓取网站图片鲜花网络营销推广方案
  • 啤酒免费代理0元铺货百度推广优化师是什么
  • 网站备案 接入商备案搜索引擎优化代理