⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 8-0-1.cpp

📁 Accelerated C++ 课后练习题 本人自己完成、可供参考
💻 CPP
字号:
#include<iostream>
#include<vector>
#include<list>
#include<string>
using namespace std;

template <class R>
R chengmax(const R& left,const R& right)
{
	return left>right?left:right;
}

template <class In,class X>
In chengfind(In begin,In end,const X& x)
{	
	if(begin==end||*begin==x)
		return begin;
	begin++;
	return chengfind(begin,end,x);
}



template <class In,class Out>
Out chengcopy(In begin,In end,Out dest)
{
	while(begin!=end)
		*dest++=*begin++;
	return dest;
}


template<class For, class X>
void chengreplace(For beg, For end,const X& x,const X& y)
{
	while(beg!=end)
	{
		if(*beg==x)
			*beg=y;
		beg++;
	}
}


template <class T>
void chengswap(T& a,T& b)
{
	T c(a);
	a=b;
	b=c;
}

template<class Bi>
void chengreverse(Bi begin,Bi end)
{
	while(begin!=end)
	{
		--end;
		if(begin!=end)
			swap(*begin++,*end);
	}
}

template<class Ran,class X>
bool binary_search(Ran begin,Ran end,const X& x)
{
	while(begin<end)
	{
		//find the midpoint of the range
		Ran mid=begin+(end-begin)/2;
		//see which part of the range contains x;keep looking only in that part
		if(x<*mid)
			end=mid;
		else if (*mid<x)
			begin=mid+1;
		//if we got here, then *mid==x so we're done
		else 
			return true;
	}
	return false;
}


int main()
{
	vector<int> v;
	//read ints from the standard input and append them to v
	chengcopy(istream_iterator<int>(cin),istream_iterator<int>(),
		back_inserter(v));

	cout<<endl;
	//cout<<"binary_search=="<<binary_search(v.begin(),v.end(),8)<<endl;
    //write the element of v each separated from the other by two space 
	chengcopy(v.begin(),v.end(),ostream_iterator<int>(cout,"  "));
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -