nothing to say, t…

来源:互联网 发布:mac怎么设置自动关机 编辑:程序博客网 时间:2024/06/06 13:26
// shit ,sina blog always trims my code ...
1.
void MY_SWAP(int & a, int &b)
{
   a = a^b;
   b = b^a;
   a = a^b;
}
2.
#define MY_SWAP(a,b,T)  do{ T temp =a; a =b;b = Temp; }while(0)
3.
template <class T>
void MY_SWAP(T&a,T&b)
{
   T temp;
   temp = a;
   a = b;
   b = temp;
}
4. 
void MY_STUPID_SWAP(T&a,T&b)
{
   MY_STACK stack;
   stack.push(a);
   stack.push(b);
   a = stack.pop();
   b = stack.pop();
}
5.template<class T>
void MY_SWAP(T* p_a,T* p_b)
{
  T temp;
  temp = *p_a;
  *p_a = *p_b;
  p_b = temp;
}

0 0