当前位置:网站首页>STL list合并
STL list合并
2022-07-21 04:34:00 【joker_0030】
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include<list>
#include<ctime>
using namespace std;
struct Node
{
int a;
char c;
//头增加ListCoutAdd()
Node(int d, int e)
{
a = d;
c = e;
}
//删除ListDeleteChange(),构成重载。ListDo()find查找重载。
bool operator ==(const Node& f)const
{
if (f.a == this->a && f.c == this->c)
{
return true;
}
return false;
}
//ListDo(),构成重载。
bool operator <(const Node& f)const//sort重载默认小于号。
{
if (f.a < this->a &&f.c <= this->c)//判定条件。从大到小。
{
return true;
}
return false;
}
};
void fun(Node& d)
{
cout << d.a << " " << d.c << endl;
}
void ListDo()
{
list<Node> db;
db.push_front(Node(15, 'b'));
db.push_front(Node(14, 'b'));
db.push_front(Node(12, 'b'));
db.push_front(Node(11, 'b'));
db.push_front(Node(13, 'b'));
db.push_back(Node(16, 'b'));
db.sort();
list <Node> db1;
db1.assign(10,Node(123, 'a'));// 赋值
//交换数值
//db1.swap(db);//db与db1交换数据。
//翻转数据
//db.reverse();
//排序
//db.sort();//成员函数排序。默认从大到小,涉及到结构体(其中的数据类型如char类型的比较)需要重载。
//合并两个列表
//db.merge(db1);//(两个列表必须是有序的,否则会崩溃,崩溃可以改结构体中重载函数中if的判定大于或小于)。
//查找。
list<Node>::iterator ite= find(db.begin(), db.end(), Node(12, 'b'));//未找到会崩溃的,在一个容器中寻找一个成员,返回这个成员的迭代器。
cout << ite->a << " "<<ite->c<<endl;
//for_each(db.begin(), db.end(), fun);
}
int main()
{
ListDo();
system("pause");
return 0;
}
边栏推荐
- 常用测试用例设计方法之边界值分析法
- 2035. 将数组分成两个数组并最小化数组和的差 折半搜索
- NXP i.MX 8M Mini 开发板规格参数,四核ARM Cortex-A53 + ARM Cortex-M4
- The ability to detect movement in vivo and build a safe and reliable payment level "face brushing" experience
- Typescript basic learning notes
- Web3流量聚合平台Starfish OS,给玩家元宇宙新范式体验
- The command of gun compiler is g++:$g++ -o prog1 prog1 cc
- Internal implementation principle of sort
- Lombok简化开发
- hot wire! The PMP project management certificate is listed in the urgently needed professional personnel
猜你喜欢
Lombok简化开发
(1)达梦数据库模型分析
Electromagnetic field and electromagnetic wave experiment II familiar with the application of MATLAB PDETOOL in two-dimensional electromagnetic problems
电磁场与电磁波实验二 熟悉Matlab PDEtool在二维电磁问题的应用
Attack and defense world ----- favorite_ number
支持向量机(理解、推导、matlab例子)
2022 the hottest free Chinese version of the whole network - free sharing of "Application Tutorial of deep learning in image processing"
(2) Dameng database matching
攻防世界----favorite_number
Classic examples of C language: 21-30 examples: insertion sort, Hill sort 1, quick sort, Hill sort 2, recursion, completion, Fibonacci sequence, common divisor and common multiple, judging the number
随机推荐
MySQL (2)
input: dynamic input is missing dimensions in profile
笔试强训第19天
Integrated design of signal processing system - minimum order IIR digital high pass filter
Assertion failed: inputs. At (2). Is Poids
Preparation of dihydrotanshinone I loaded albumin nanoparticles / norcantharidin albumin nanoparticles / voriconazole albumin nanoparticles
input: dynamic input is missing dimensions in profile
信号处理系统综合设计-最小阶数的IIR数字高通滤波器
Classic examples of C language: 21-30 examples: insertion sort, Hill sort 1, quick sort, Hill sort 2, recursion, completion, Fibonacci sequence, common divisor and common multiple, judging the number
2035. Divide the array into two arrays and minimize the difference and half search of the array sum
STM32——ADC读取光敏传感器控制LED灯,看门狗中断
全志A40i开发板硬件说明书——100%国产+工业级方案(中)
Assertion failed: inputs. at(2). is_ weights
【To .NET】.NET Core Web API开发流程知识点整理[进阶]
Experiment 3 of wireless location technology simulation of location fingerprint location based on signal strength
Siyuan synchronization problem: cloud object not found v2.1.0
项目中生成MultipartFile并调用其它服务
The ability to detect movement in vivo and build a safe and reliable payment level "face brushing" experience
Machine learning sklearn dataset
Unittest test test framework principle and test process analysis are definitely improved after reading