当前位置:网站首页>STL list output and addition
STL list output and addition
2022-07-21 19:55:00 【joker_ 0030】
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include<list>
#include<ctime>
using namespace std;
struct Node
{
int a;
char c;
// Head increase
Node(int d, int e)
{
a = d;
c = e;
}
};
void fun(Node& d)
{
cout << d.a << " " << d.c << endl;
}
void ListCoutAdd()
{
// Output
/*Node no = { 12, 'a' };
list<Node> db1(6, no);*/
// Iterator loop output .
/*for (list<Node>::iterator ite = db1.begin(); ite != db1.end(); ite++)
{
cout << ite->a << " " << ite->c << endl;
}*/
// Output
//cout << db1.back().a << " " << db1.back().c << endl;//back() Function returns a reference , Point to list The last element .
//cout << db1.front().a << " " << db1.front().c << endl; //back() Function returns a reference , Point to list First element .
// Head increase
/*list <Node> db;
db.push_front(Node(12, 'b'));
for_each(db.begin(), db.end(), fun);
db.push_front(Node(13, 'c'));
for_each(db.begin(), db.end(), fun);*/
// Add at the end
/*list <Node> db2;
db2.push_front(Node(12, 'b'));
db2.push_back(Node(13, 'c'));
for_each(db2.begin(), db2.end(), fun);*/
// Add... In the middle
list <Node> db2;
list <Node> db3;
db3.push_front(Node(16, 'b'));
db3.push_front(Node(16, 'b'));
db3.push_front(Node(16, 'b'));
db3.push_back(Node(16, 'b'));
db2.push_front(Node(12, 'b'));
db2.push_back(Node(13, 'c'));
list<Node>::iterator ite = db2.begin(); // iterator
ite++;// Shift subscript to second place .( Data second , Subscript to be 1)
//db2.insert(ite, Node(15, 'd'));// Insert an element .
//db2.insert(ite,3,Node(16, 'e'));// Insert 3( many ) Elements .
db2.insert(ite,++db3.begin(),db3.end());// stay db2 The middle subscript position is 1( Data second , Subscript to be 1) Insert db3 Subscript is [1,3) The elements of .
for_each(db2.begin(), db2.end(), fun);
}
int main()
{
ListCoutAdd();
system("pause");
return 0;
}
边栏推荐
- 微信小程序-云数据库开发
- 【transformer】ViT
- 元宇宙iwemeta:风口上的脑机接口,偷偷的解密大脑
- STL list合并
- Sword finger offer special assault version day 5
- Wireless location technology experiment II TDOA least square location method
- Written examination mandatory training day 20
- 数据中台、BI业务访谈(二):组织架构梳理的坑
- Iwemeta: Shi Yuzhu's golden sauce wine: OEM factories have been shut down. Who is producing it?
- C language learning
猜你喜欢
(1) Analysis of Damon database model
Electromagnetic field and electromagnetic wave experiment II familiar with the application of MATLAB PDETOOL in two-dimensional electromagnetic problems
From graphic design to software testing, I like to raise 11k+13 salary. Looking back, I'm very lucky
Sequence model (I) - cyclic sequence model
STM32 - ADC reads the photosensitive sensor, controls the LED light, and the watchdog interrupts
Why write unit tests? How to write unit tests?
My understanding of UI automated testing
Unittest test test framework principle and test process analysis are definitely improved after reading
Getting started with the gradle project construction tool
NXP i.MX 8m Mini development board specifications, quad core arm cortex-a53 + arm cortex-m4
随机推荐
Unity ECS 测试Demo
MyCat的介绍与安装以及基本使用
GUN编译器的命令是g++:$ g++ -o prog1 prog1.cc
(2) Dameng database matching
【To .NET】.NET Core Web API开发流程知识点整理[入门]
ctfshow MengXIn misc1
869. 试除法求约数
868. 筛质数
Sword finger offer special assault version day 5
Unittest test test framework principle and test process analysis are definitely improved after reading
微信小程序-云数据库开发
【transformer】ViT
JSP页面
Quanzhi a40i development board hardware specification - 100% domestic + industrial level scheme (Part 1)
STL list输出和增加
[C exercise] macro realizes the exchange of digital binary parity bits
Assertion failed: inputs.at(2).is_weights
odoo神操作后台调用路由接口
Attack and defense world ----- favorite_ number
Jenkins怎么发邮件,自动化大老手把手教你