All pastes #761272 Raw Edit

Mine

public text v1 · immutable
·published 2007-11-04 19:20 UTC
rendered paste body
#include <iostream>
#include <vector>

template< typename Container, typename T > void sort( Container & con ){
	int len = con.size();
	T n, l;
	bool c = false;
	for( int i = 0; i < len-1; i++ ){
		n = con[i];
		l = con[i+1];
		if( n > l ){
			c = true;
			con[i] = l;
			con[i+1] = n;
		}
		if( i == len -2 &&  !c )
			return;
	}
	sort< Container, T >( con );
}

int main(){
	
/////////// INT ////////////////////
	std::vector<int> VecInt;
	
	VecInt.push_back( 18 );
	VecInt.push_back( 8 );
	VecInt.push_back( 3 );
	VecInt.push_back( 5 );
	VecInt.push_back( 1 );
	VecInt.push_back( 19 );
	VecInt.push_back( 9);
	
	sort< std::vector<int>, int >( VecInt );
	
	std::vector<int>::iterator IterInt = VecInt.begin();
	while( IterInt != VecInt.end() ){
		std::cout<< *IterInt << std::endl;
		IterInt++;
	}
/////////////////////////////////////
////////// FLOAT ///////////////////
	std::vector<float> VecFloat;
	
	VecFloat.push_back( 1.9 );
	VecFloat.push_back( 1.0 );
	VecFloat.push_back( 0.9 );
	VecFloat.push_back( 5.8 );
	VecFloat.push_back( 1.7 );
	VecFloat.push_back( 3.5 );
	VecFloat.push_back( 4.3 );
	
	sort< std::vector<float>, float >( VecFloat );
	
	std::vector<float>::iterator IterFloat = VecFloat.begin();
	while( IterFloat != VecFloat.end() ){
		std::cout<< *IterFloat << std::endl;
		IterFloat++;
	}
///////////////////////////////////////////
///////// STRING /////////////////////////
	std::vector< std::string > VecString;
	VecString.push_back( "teste" );
	VecString.push_back( "tes" );
	VecString.push_back( "t" );
	VecString.push_back( "testeteste" );
	
	sort< std::vector<std::string>, std::string >( VecString );
	
	std::vector<std::string>::iterator IterString = VecString.begin();
	while( IterString != VecString.end() ){
		std::cout<< *IterString << std::endl;
		IterString++;
	}
//////////////////////////////////////////////
	return 0;
}

/*output
./teste
1
3
5
8
9
18
19
0.9
1
1.7
1.9
3.5
4.3
5.8
t
tes
teste
testeteste
*/