STL(4)adjacent_find函数

21 篇文章 1 订阅
/*
	// TEMPLATE FUNCTION adjacent_find
template<class _FwdIt> inline
	_FwdIt _Adjacent_find(_FwdIt _First, _FwdIt _Last)
	{	// find first matching successor
	_DEBUG_RANGE(_First, _Last);
	for (_FwdIt _Firstb; (_Firstb = _First) != _Last && ++_First != _Last; )
		if (*_Firstb == *_First)
			return (_Firstb);
	return (_Last);
	}

template<class _FwdIt> inline
	_FwdIt adjacent_find(_FwdIt _First, _FwdIt _Last)
	{	// find first matching successor
	_ASSIGN_FROM_BASE(_First,
		_Adjacent_find(_CHECKED_BASE(_First), _CHECKED_BASE(_Last)));
	return (_First);
	}
	*/


//*********************by vincent http://my.csdn.net/sunboyiris  ************************//
#include "stdafx.h"
#include "algorithm"
#include "list"
#include "iostream"
using namespace std;

bool fun(int x)
{return x%3?false:true;}
int _tmain(int argc, _TCHAR* argv[])
{
	list<int> l;
	for(int i=100;i<110;i++)
	{
	l.push_back(i);
	}
    for(int i=109;i<116;i++)
	{
	l.push_back(i);
	}
	//引用指针
	int count1=0;
	list<int>::iterator iter;
	for(iter=l.begin();iter!=l.end();iter++)
	{ 
	count1++;cout<<*iter<<endl;
	}
	cout<<count1<<endl;

	
	list<int>::iterator iter1=adjacent_find(l.begin(),l.end());
	if(iter1!=l.end())
	{
	cout<<"有相邻的元素相等"<<endl;
	cout<<"其元素为"<<*(iter1)<<" "<<*(++iter1)<<endl;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值