Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > C/C++ > algorithm 修改性的序列操作源码
【标  题】:algorithm 修改性的序列操作源码
【关键字】:algorithm
【来  源】:http://blog.csdn.net/steven216/archive/2007/02/20/1512020.aspx

algorithm 修改性的序列操作源码

Your Ad Here


// TEMPLATE FUNCTION transform WITH UNARY OP
template<class _II, class _OI, class _Uop> inline
 _OI transform(_II _F, _II _L, _OI _X, _Uop _U)
 {for (; _F != _L; ++_F, ++_X)
  *_X = _U(*_F);
 return (_X); }
  // TEMPLATE FUNCTION transform WITH BINARY OP
template<class _II1, class _II2, class _OI, class _Bop> inline
 _OI transform(_II1 _F1, _II1 _L1, _II2 _F2, _OI _X, _Bop _B)
 {for (; _F1 != _L1; ++_F1, ++_F2, ++_X)
  *_X = _B(*_F1, *_F2);
 return (_X); }

  // TEMPLATE FUNCTION copy
template<class _II, class _OI> inline
 _OI copy(_II _F, _II _L, _OI _X)
 {for (; _F != _L; ++_X, ++_F)
  *_X = *_F;
 return (_X); }
  // TEMPLATE FUNCTION copy_backward
template<class _BI1, class _BI2> inline
 _BI2 copy_backward(_BI1 _F, _BI1 _L, _BI2 _X)
 {while (_F != _L)
  *--_X = *--_L;
 return (_X); }

template<class _Ty> inline
 void swap(_Ty& _X, _Ty& _Y)
 {_Ty _Tmp = _X;
 _X = _Y, _Y = _Tmp; }
  // TEMPLATE FUNCTION iter_swap
template<class _FI1, class _FI2> inline
 void iter_swap(_FI1 _X, _FI2 _Y)
 {_Iter_swap(_X, _Y, _Val_type(_X)); }
template<class _FI1, class _FI2, class _Ty> inline
 void _Iter_swap(_FI1 _X, _FI2 _Y, _Ty *)
 {_Ty _Tmp = *_X;
 *_X = *_Y, *_Y = _Tmp; }
  // TEMPLATE FUNCTION swap_ranges
template<class _FI1, class _FI2> inline
 _FI2 swap_ranges(_FI1 _F, _FI1 _L, _FI2 _X)
 {for (; _F != _L; ++_F, ++_X)
  iter_swap(_F, _X);
 return (_X); }
  // TEMPLATE FUNCTION replace
template<class _FI, class _Ty> inline
 void replace(_FI _F, _FI _L, const _Ty& _Vo, const _Ty& _Vn)
 {for (; _F != _L; ++_F)
  if (*_F == _Vo)
   *_F = _Vn; }
  // TEMPLATE FUNCTION replace_if
template<class _FI, class _Pr, class _Ty> inline
 void replace_if(_FI _F, _FI _L, _Pr _P, const _Ty& _V)
 {for (; _F != _L; ++_F)
  if (_P(*_F))
   *_F = _V; }
  // TEMPLATE FUNCTION generate
template<class _FI, class _Gen> inline
 void generate(_FI _F, _FI _L, _Gen _G)
 {for (; _F != _L; ++_F)
  *_F = _G(); }
  // TEMPLATE FUNCTION generate_n
template<class _OI, class _Pd, class _Gen> inline
 void generate_n(_OI _F, _Pd _N, _Gen _G)
 {for (; 0 < _N; --_N, ++_F)
  *_F = _G(); }
  // TEMPLATE FUNCTION remove
template<class _FI, class _Ty> inline
 _FI remove(_FI _F, _FI _L, const _Ty& _V)
 {_F = find(_F, _L, _V);
 if (_F == _L)
  return (_F);
 else
  {_FI _Fb = _F;
  return (remove_copy(++_F, _L, _Fb, _V)); }}
  // TEMPLATE FUNCTION remove_if
template<class _FI, class _Pr> inline
 _FI remove_if(_FI _F, _FI _L, _Pr _P)
 {_F = find_if(_F, _L, _P);
 if (_F == _L)
  return (_F);
 else
  {_FI _Fb = _F;
  return (remove_copy_if(++_F, _L, _Fb, _P)); }}
  // TEMPLATE FUNCTION remove_copy
template<class _II, class _OI, class _Ty> inline
 _OI remove_copy(_II _F, _II _L, _OI _X, const _Ty& _V)
 {for (; _F != _L; ++_F)
  if (!(*_F == _V))
   *_X++ = *_F;
 return (_X); }
  // TEMPLATE FUNCTION remove_copy_if
template<class _II, class _OI, class _Pr> inline
 _OI remove_copy_if(_II _F, _II _L, _OI _X, _Pr _P)
 {for (; _F != _L; ++_F)
  if (!_P(*_F))
   *_X++ = *_F;
 return (_X); }
  // TEMPLATE FUNCTION unique
template<class _FI> inline
 _FI unique(_FI _F, _FI _L)
 {_F = adjacent_find(_F, _L);
 return (unique_copy(_F, _L, _F)); }
  // TEMPLATE FUNCTION unique WITH PRED
template<class _FI, class _Pr> inline
 _FI unique(_FI _F, _FI _L, _Pr _P)
 {_F = adjacent_find(_F, _L, _P);
 return (unique_copy(_F, _L, _F, _P)); }
  // TEMPLATE FUNCTION unique_copy
template<class _II, class _OI> inline
 _OI unique_copy(_II _F, _II _L, _OI _X)
 {return (_F == _L ? _X :
  _Unique_copy(_F, _L, _X, _Iter_cat(_F))); }
template<class _II, class _OI> inline
 _OI _Unique_copy(_II _F, _II _L, _OI _X, input_iterator_tag)
 {return (_Unique_copy(_F, _L, _X, _Val_type(_F))); }
template<class _II, class _OI, class _Ty> inline
 _OI _Unique_copy(_II _F, _II _L, _OI _X, _Ty *)
 {_Ty _V = *_F;
 for (*_X++ = _V; ++_F != _L; )
  if (!(_V == *_F))
   _V = *_F, *_X++ = _V;
 return (_X); }
template<class _FI, class _OI> inline
 _OI _Unique_copy(_FI _F, _FI _L, _OI _X, forward_iterator_tag)
 {_FI _Fb = _F;
 for (*_X++ = *_Fb; ++_F != _L; )
  if (!(*_Fb == *_F))
   _Fb = _F, *_X++ = *_Fb;
 return (_X); }
template<class _BI, class _OI> inline
 _OI _Unique_copy(_BI _F, _BI _L, _OI _X,
  bidirectional_iterator_tag)
 {return (_Unique_copy(_F, _L, _X, forward_iterator_tag())); }
template<class _RI, class _OI> inline
 _OI _Unique_copy(_RI _F, _RI _L, _OI _X,
  random_access_iterator_tag)
 {return (_Unique_copy(_F, _L, _X, forward_iterator_tag())); }
  // TEMPLATE FUNCTION unique_copy WITH PRED
template<class _II, class _OI, class _Pr> inline
 _OI unique_copy(_II _F, _II _L, _OI _X, _Pr _P)
 {return (_F == _L ? _X :
  _Unique_copy(_F, _L, _X, _P, _Iter_cat(_F))); }
template<class _II, class _OI, class _Pr> inline
 _OI _Unique_copy(_II _F, _II _L, _OI _X, _Pr _P,
  input_iterator_tag)
 {return (_Unique_copy(_F, _L, _X, _P, _Val_type(_F))); }
template<class _II, class _OI, class _Ty, class _Pr> inline
 _OI _Unique_copy(_II _F, _II _L, _OI _X, _Pr _P, _Ty *)
 {_Ty _V = *_F;
 for (*_X++ = _V; ++_F != _L; )
  if (!_P(_V, *_F))
   _V = *_F, *_X++ = _V;
 return (_X); }
template<class _FI, class _OI, class _Pr> inline
 _OI _Unique_copy(_FI _F, _FI _L, _OI _X, _Pr _P,
  forward_iterator_tag)
 {_FI _Fb = _F;
 for (*_X++ = *_Fb; ++_F != _L; )
  if (!_P(*_Fb, *_F))
   _Fb = _F, *_X++ = *_Fb;
 return (_X); }
template<class _BI, class _OI, class _Pr> inline
 _OI _Unique_copy(_BI _F, _BI _L, _OI _X, _Pr _P,
  bidirectional_iterator_tag)
 {return (_Unique_copy(_F, _L, _X, _P,
  forward_iterator_tag())); }
template<class _RI, class _OI, class _Pr> inline
 _OI _Unique_copy(_RI _F, _RI _L, _OI _X, _Pr _P,
  random_access_iterator_tag)
 {return (_Unique_copy(_F, _L, _X, _P,
  forward_iterator_tag())); }

底层DLL屏蔽任意键:【上一篇】
algorithm 非修改性序列操作源码:【下一篇】
【相关文章】
  • 设计总结2,关于template method 或者algorithm skeleton的一个应用
  • Speech:Intorduction to Heuristics Algorithm------A* Algorithm
  • Fit the Hardware to the Algorithm with SystemC Mod
  • Sorting Algorithms
  • Sort of Algorithm
  • 看《Algorithm Design and Analysis》笔记 陆续添加中...
  • Liang-Barsky Algorithms
  • Sort algorithm in Haskell
  • 学习《Introduction to Algorithms》六
  • 学习《Introduction to Algorithms》五
  • 【随机文章】
  • Jsp-Tip-1-servlet
  • VC中创建不可改变大小的窗口,及其限制窗口大小的办法
  • 突破TCP-IP过滤/防火墙进入内网(icmp篇)
  • GDI编程基础(转贴)
  • 面对几个错误的解决关键
  • 在 Linux 下用户空间与内核空间数据交换的方式,第 2 部分: procfs、seq_file、debugfs和relayfs
  • FLIC动画文件的播放程序设计
  • 对Shttpd的研究(一)
  • VB设计Win2000下截获IP数据包程序
  • 免费的个人帐户Q币[有效期2004.3.22--3.31]
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.