STL algorithm - 1

惭愧啊,自己还是容易受到外界影响,今天只花了3个小时学习算法,

中午看到同学在玩DDCTF就上手做了一题,没想到就没停下来..撸了7个小时逆向..没有时间整理知识了..

导致今天的计划没有完成.

又要肝一会了..洗个澡先...

以下是对f_zyj大佬模板中提供的algorithm算法库相关函数的测试和注解

f_zyj大佬的博客:

http://blog.csdn.net/f_zyj/article/details/51594851

地址为pdf中第21页

#define pause system("pause");
#define fence puts("-------------");
#define endline puts("")
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;


int main()
{
	//adjacent_find(first,last(,cmp))
	//STL非变易算法(Non-mutating algorithms)
	//是一组不破坏操作数据的模板函数,
	//用来对序列数据进行逐个处理、元素查找、子序列搜索、统计和匹配。
	//功能:查找一个迭代器区间内,相等或满足自定义条件的第一个邻近元素对
	//返回:找到的一个元素对的第一个元素的位置,
	//     找不到返回last位置
	vector<int>a;
	a.push_back(0);
	a.push_back(1);
	a.push_back(1);
	a.push_back(2);
	auto j1 = adjacent_find(a.begin(), a.end());
	auto j2 = adjacent_find(a.begin(), a.end(), [](int n, int m) { return n < m; });
	cout << *j1 << " " << *j2;
	endline;
	fence;
	//binary_search
	//功能:查找一个有序迭代器区间内是否存在某个元素
	//返回:true false
	auto bs = binary_search(a.begin(), a.end(), 1);
	cout << bs;
	endline;
	fence;
	//copy
	//功能:将一个迭代器区间的内容复制到另一个迭代器区间
	//(利用这个函数进行输出输入见上一篇博客iterator)
	vector<int>c(4);
	auto tc = copy(a.begin(), a.end(), c.begin());
	for (auto i : c)cout << i << " ";
	endline;
	fence
	pause
}
/*
运行结果
1 0
-------------
1
-------------
0 1 1 2
-------------
*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值