swap.h
来自「新的二维数组以及映射的快速算法的C语言实现.」· C头文件 代码 · 共 52 行
H
52 行
#ifndef __SWAP_H__
#define __SWAP_H__
// swaps two elements
template<class T> inline void Swap(T& x, T& y)
{
T temp;
temp = x;
x = y;
y = temp;
}
// swaps two elements and returns value
// usefull for situation when need return old value
template<class T> inline T& SwapRet(T& x, T& y)
{
T temp;
temp = x;
x = y;
y = temp;
return x;
}
// template function returns y if x < y
// To avoid conflicts with min and max in WINDEF.H
template<class T> inline const T& Max(const T& x, const T& y)
{
if(x > y)
{
return x;
}
return y;
}
// template function returns y if x > y
// To avoid conflicts with min and max in WINDEF.H
template<class T> inline const T& Min(const T& x, const T& y)
{
if(x < y)
{
return x;
}
return y;
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?