データ構造とアルゴリズム分析の悟り


#include
#include
#include
#include
#include
using namespace std;


const int & findMax(const vector &vec)
{
	size_t max=0;
	for(size_t i=1;i!=vec.size();i++)
	{
		if(vec[i]>vec[max])
			max=i;
	}
	return vec[max];
}


/*     ,           ,         maxValue         。*/
const int& findMaxError(const vector &vec)
{
	string::value_type maxValue=vec[0];
	for(size_t i=1;i!=vec.size();i++)
		if(vec[i]>maxValue)
			maxValue=vec[i];
	return maxValue;
}
int main(){
	istream_iterator in(cin),eof;
	vector vec(in,eof);
	ostream_iterator out(cout," ");
	copy(vec.begin(),vec.end(),out);
	cout<
/*   vs   */
/*   :     ,           */
/*           ,     ,     ,        ,
          ,     ,            */
#include
using namespace std;

class IntCell{
public:
	explicit IntCell(int i=0);
	int read()const;
	void write(int x);
	IntCell(const IntCell &);
	const IntCell &operator=(const IntCell &);
	~IntCell();
private:
	int *storeValue;
};


IntCell::IntCell(int i)
{
	storeValue=new int(i);
}

int IntCell::read()const
{
	return *storeValue;
}

void IntCell::write(int x)
{
	*storeValue=x;
}

IntCell::IntCell(const IntCell &rhs)
{
	storeValue=new int(*rhs.storeValue);
}

/*    ,          ,       */
const IntCell & IntCell::operator =(const IntCell &rhs)
{
	if(this!=&rhs)
		*storeValue=*rhs.storeValue;
	return *this;
}

IntCell::~IntCell()
{
	delete storeValue;
}


int main(){
	IntCell a(2);
	IntCell b=a;/*  */
	IntCell c;

	c=b;/*  */
	a.write(4);
	/*    ,    4,4,4*/
	/*    ,    4,2,2*/
	cout<
#ifndef WEIWEI_H
#define WEIWEI_H

#include
#include
#include
using std::string;
using std::vector;

template 
const object & findMax(const vector &vec)
{
	return findMax(vec,less());
}

template 
const object & findMax(const vector &vec,comparator isLessThan)
{
	size_t max=0;
	for(size_t i=1;i!=vec.size();i++)
		if(isLessThan(vec[max],vec[i]))
			max=i;
	return vec[max];

}


class CaseInsensitiveCompare{
public:
	bool operator()(const string &lhs,const string &rhs)const
	{
		return _stricmp(lhs.c_str(),rhs.c_str())<0;
	}
};



#endif
#include"weiwei.h"
#include
#include
using namespace std;

int main(){
	vector arr(3);
	arr[0]="Zee";
	arr[1]="alligator";
	arr[2]="crocodile";
	cout<