블로그 이미지

[정렬][C++] Template를 이용한 Swap 함수

2013. 1. 30. 23:04

[정렬][C++]

Swap Function(스왑 함수)

 template<typename T>
void swap(T& _input1, T& _input2)
{
	T Temp = _input1;
	_input1 = _input2;
	_input2 = Temp;
}


예제)

 int main(void)
{

int a=5, b=7; char c = 'c', d = 'd'; swap(a, b); swap(c, d); cout << "a = "<< a << ", b = "<< b << endl; cout << "c = "<< c << ", d = "<< d << endl; return 0; }