1 Star 1 Fork 0

AlbertDarren / STL

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sequenceContainerOperations6.cpp 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
AlbertDarren 提交于 2022-04-03 00:55 . first commit
/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
using namespace std;
void show(auto container,string sep=" ")
{
for(auto ele:container)
{
cout << ele << " ";
}
cout << endl;
}
int main_16()
{
list<string> str_list({"Apple","Banana","Blueberry","Pear","Orange","Grapes","Strawberry"});
show(str_list);
cout << "delete the first element" << endl;
str_list.pop_front();
show(str_list);
cout << "delete the last element" << endl;
str_list.pop_back();
show(str_list);
string fruits[]= {"Pear","Watermelon"};
for(string fruit:fruits)
{
auto iter=find(str_list.begin(),str_list.end(),fruit);
if (iter!=str_list.end())
{
str_list.erase(iter);
cout << fruit<<" Exist" << endl;
cout << "delete "<<fruit << endl;
}
else
{
cout << fruit<< " doesn't exist" << endl;
}
show(str_list);
}
str_list.erase(++str_list.begin(),--str_list.end());
cout << "delete a range" << endl;
show(str_list);
str_list.clear();
cout << "clear" << endl;
show(str_list);
return 0;
}
C++
1
https://gitee.com/AlbertDarren_admin/stl.git
git@gitee.com:AlbertDarren_admin/stl.git
AlbertDarren_admin
stl
STL
master

搜索帮助