⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slist

📁 c++编程宝典源码及Quincy99编译器 是《标准C++编程宝典》电子工业出版社的光盘
💻
📖 第 1 页 / 共 3 页
字号:
  }  // Linear in distance(begin(), __pos), in distance(__x.begin(), __first),  // and in distance(__first, __last).  void splice(iterator __pos, slist& __x, iterator __first, iterator __last)  {    if (__first != __last)      __slist_splice_after(__slist_previous(&_M_head, __pos._M_node),                           __slist_previous(&__x._M_head, __first._M_node),                           __slist_previous(__first._M_node, __last._M_node));  }public:  void reverse() {     if (_M_head._M_next)      _M_head._M_next = __slist_reverse(_M_head._M_next);  }  void remove(const _Tp& __val);   void unique();   void merge(slist& __x);  void sort();     #ifdef __STL_MEMBER_TEMPLATES  template <class _Predicate>   void remove_if(_Predicate __pred);  template <class _BinaryPredicate>   void unique(_BinaryPredicate __pred);   template <class _StrictWeakOrdering>   void merge(slist&, _StrictWeakOrdering);  template <class _StrictWeakOrdering>   void sort(_StrictWeakOrdering __comp); #endif /* __STL_MEMBER_TEMPLATES */};template <class _Tp, class _Alloc>slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x){  if (&__x != this) {    _Node_base* __p1 = &_M_head;    _Node* __n1 = (_Node*) _M_head._M_next;    const _Node* __n2 = (const _Node*) __x._M_head._M_next;    while (__n1 && __n2) {      __n1->_M_data = __n2->_M_data;      __p1 = __n1;      __n1 = (_Node*) __n1->_M_next;      __n2 = (const _Node*) __n2->_M_next;    }    if (__n2 == 0)      _M_erase_after(__p1, 0);    else      _M_insert_after_range(__p1, const_iterator((_Node*)__n2),                                   const_iterator(0));  }  return *this;}template <class _Tp, class _Alloc>void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {  _Node_base* __prev = &_M_head;  _Node* __node = (_Node*) _M_head._M_next;  for ( ; __node != 0 && __n > 0 ; --__n) {    __node->_M_data = __val;    __prev = __node;    __node = (_Node*) __node->_M_next;  }  if (__n > 0)    _M_insert_after_fill(__prev, __n, __val);  else    _M_erase_after(__prev, 0);}#ifdef __STL_MEMBER_TEMPLATEStemplate <class _Tp, class _Alloc> template <class _InputIter>voidslist<_Tp, _Alloc>::_M_assign_dispatch(_InputIter __first, _InputIter __last,                                      __false_type){  _Node_base* __prev = &_M_head;  _Node* __node = (_Node*) _M_head._M_next;  while (__node != 0 && __first != __last) {    __node->_M_data = *__first;    __prev = __node;    __node = (_Node*) __node->_M_next;    ++__first;  }  if (__first != __last)    _M_insert_after_range(__prev, __first, __last);  else    _M_erase_after(__prev, 0);}#endif /* __STL_MEMBER_TEMPLATES */template <class _Tp, class _Alloc>inline bool operator==(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2){  typedef typename slist<_Tp,_Alloc>::_Node _Node;  _Node* __n1 = (_Node*) _SL1._M_head._M_next;  _Node* __n2 = (_Node*) _SL2._M_head._M_next;  while (__n1 && __n2 && __n1->_M_data == __n2->_M_data) {    __n1 = (_Node*) __n1->_M_next;    __n2 = (_Node*) __n2->_M_next;  }  return __n1 == 0 && __n2 == 0;}template <class _Tp, class _Alloc>inline bool operator<(const slist<_Tp,_Alloc>& _SL1,                      const slist<_Tp,_Alloc>& _SL2){  return lexicographical_compare(_SL1.begin(), _SL1.end(),                                  _SL2.begin(), _SL2.end());}#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDERtemplate <class _Tp, class _Alloc>inline void swap(slist<_Tp,_Alloc>& __x, slist<_Tp,_Alloc>& __y) {  __x.swap(__y);}#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */template <class _Tp, class _Alloc>void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x){  _Node_base* __cur = &_M_head;  while (__cur->_M_next != 0 && __len > 0) {    --__len;    __cur = __cur->_M_next;  }  if (__cur->_M_next)     _M_erase_after(__cur, 0);  else    _M_insert_after_fill(__cur, __len, __x);}template <class _Tp, class _Alloc>void slist<_Tp,_Alloc>::remove(const _Tp& __val){  _Node_base* __cur = &_M_head;  while (__cur && __cur->_M_next) {    if (((_Node*) __cur->_M_next)->_M_data == __val)      _M_erase_after(__cur);    else      __cur = __cur->_M_next;  }}template <class _Tp, class _Alloc> void slist<_Tp,_Alloc>::unique(){  _Node_base* __cur = _M_head._M_next;  if (__cur) {    while (__cur->_M_next) {      if (((_Node*)__cur)->_M_data ==           ((_Node*)(__cur->_M_next))->_M_data)        _M_erase_after(__cur);      else        __cur = __cur->_M_next;    }  }}template <class _Tp, class _Alloc>void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x){  _Node_base* __n1 = &_M_head;  while (__n1->_M_next && __x._M_head._M_next) {    if (((_Node*) __x._M_head._M_next)->_M_data <         ((_Node*)       __n1->_M_next)->_M_data)       __slist_splice_after(__n1, &__x._M_head, __x._M_head._M_next);    __n1 = __n1->_M_next;  }  if (__x._M_head._M_next) {    __n1->_M_next = __x._M_head._M_next;    __x._M_head._M_next = 0;  }}template <class _Tp, class _Alloc>void slist<_Tp,_Alloc>::sort(){  if (_M_head._M_next && _M_head._M_next->_M_next) {    slist __carry;    slist __counter[64];    int __fill = 0;    while (!empty()) {      __slist_splice_after(&__carry._M_head, &_M_head, _M_head._M_next);      int __i = 0;      while (__i < __fill && !__counter[__i].empty()) {        __counter[__i].merge(__carry);        __carry.swap(__counter[__i]);        ++__i;      }      __carry.swap(__counter[__i]);      if (__i == __fill)        ++__fill;    }    for (int __i = 1; __i < __fill; ++__i)      __counter[__i].merge(__counter[__i-1]);    this->swap(__counter[__fill-1]);  }}#ifdef __STL_MEMBER_TEMPLATEStemplate <class _Tp, class _Alloc> template <class _Predicate>void slist<_Tp,_Alloc>::remove_if(_Predicate __pred){  _Node_base* __cur = &_M_head;  while (__cur->_M_next) {    if (__pred(((_Node*) __cur->_M_next)->_M_data))      _M_erase_after(__cur);    else      __cur = __cur->_M_next;  }}template <class _Tp, class _Alloc> template <class _BinaryPredicate> void slist<_Tp,_Alloc>::unique(_BinaryPredicate __pred){  _Node* __cur = (_Node*) _M_head._M_next;  if (__cur) {    while (__cur->_M_next) {      if (__pred(((_Node*)__cur)->_M_data,                  ((_Node*)(__cur->_M_next))->_M_data))        _M_erase_after(__cur);      else        __cur = (_Node*) __cur->_M_next;    }  }}template <class _Tp, class _Alloc> template <class _StrictWeakOrdering>void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x,                             _StrictWeakOrdering __comp){  _Node_base* __n1 = &_M_head;  while (__n1->_M_next && __x._M_head._M_next) {    if (__comp(((_Node*) __x._M_head._M_next)->_M_data,               ((_Node*)       __n1->_M_next)->_M_data))      __slist_splice_after(__n1, &__x._M_head, __x._M_head._M_next);    __n1 = __n1->_M_next;  }  if (__x._M_head._M_next) {    __n1->_M_next = __x._M_head._M_next;    __x._M_head._M_next = 0;  }}template <class _Tp, class _Alloc> template <class _StrictWeakOrdering> void slist<_Tp,_Alloc>::sort(_StrictWeakOrdering __comp){  if (_M_head._M_next && _M_head._M_next->_M_next) {    slist __carry;    slist __counter[64];    int __fill = 0;    while (!empty()) {      __slist_splice_after(&__carry._M_head, &_M_head, _M_head._M_next);      int __i = 0;      while (__i < __fill && !__counter[__i].empty()) {        __counter[__i].merge(__carry, __comp);        __carry.swap(__counter[__i]);        ++__i;      }      __carry.swap(__counter[__i]);      if (__i == __fill)        ++__fill;    }    for (int __i = 1; __i < __fill; ++__i)      __counter[__i].merge(__counter[__i-1], __comp);    this->swap(__counter[__fill-1]);  }}#endif /* __STL_MEMBER_TEMPLATES */// Specialization of insert_iterator so that insertions will be constant// time rather than linear time.#ifdef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class _Tp, class _Alloc>class insert_iterator<slist<_Tp, _Alloc> > {protected:  typedef slist<_Tp, _Alloc> _Container;  _Container* container;  typename _Container::iterator iter;public:  typedef _Container          container_type;  typedef output_iterator_tag iterator_category;  typedef void                value_type;  typedef void                difference_type;  typedef void                pointer;  typedef void                reference;  insert_iterator(_Container& __x, typename _Container::iterator __i)     : container(&__x) {    if (__i == __x.begin())      iter = __x.before_begin();    else      iter = __x.previous(__i);  }  insert_iterator<_Container>&  operator=(const typename _Container::value_type& __value) {     iter = container->insert_after(iter, __value);    return *this;  }  insert_iterator<_Container>& operator*() { return *this; }  insert_iterator<_Container>& operator++() { return *this; }  insert_iterator<_Container>& operator++(int) { return *this; }};#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)#pragma reset woff 1174#pragma reset woff 1375#endif__STL_END_NAMESPACE #endif /* _CPP_BITS_STL_SLIST_H */// Local Variables:// mode:C++// End:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -