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

📄 tsll.cc

📁 线程池 线程池 线程池
💻 CC
字号:
//// Project   : threadpool// File      : TSLL.cc// Author    : Ronald Kriemann// Purpose   : Template class for a single concatenated list//// Copyright (C) 2003 - Ronald Kriemann//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA//template <class T>TSLL<T> &TSLL<T>::prepend ( const T & elem ){    TItem  * tmp = new TItem( elem, _first );        _first = tmp;    _size++;    if (_last == NULL)        _last = tmp;        return *this;}template <class T>TSLL<T> &TSLL<T>::append ( const T & elem ){    TItem * tmp = new TItem( elem );        if (_last)        _last->_next = tmp;        _last = tmp;        if ( ! _first )        _first = tmp;        _size++;        return *this;}template <class T>voidTSLL<T>::remove ( const T & elem ){    TItem  * item = _first;    TItem  * old  = NULL;    while (item != NULL)    {        if (item->_data == elem)        {            if (item == _first)                _first = item->_next;            else // (item != first) => (old != NULL)                old->_next = item->_next;            if (item == _last)                _last = old;                        delete item;            _size--;            if ( old == NULL )                item = _first;            else                item = old->_next;        }// if        else        {            old  = item;            item = item->_next;        }// else    }// while}template <class T>voidTSLL<T>::remove_first (){    if (_first)    {        TItem  * tmp = _first->_next;        delete _first;        if (tmp == NULL)            _last = NULL;        _first = tmp;        _size--;    }// if}template <class T>TTSLL<T>::behead (){    assert( _first != NULL );    T        ret = _first->_data;    TItem  * tmp = _first->_next;    delete _first;    if (tmp == NULL)        _last = NULL;        _first = tmp;        _size--;        return ret;}template <class T>voidTSLL<T>::remove_all (){    if (_size == 0)        return;        TItem * tmp = _first;    TItem * next;        while (tmp != NULL)    {        next = tmp->_next;        delete tmp;        tmp = next;    }// while        _first = _last = NULL;    _size = 0;}template <class T>voidTSLL<T>::copy ( const TSLL< T > & list ){    TItem  * tmp  = list._first;    TItem  * old  = NULL;    TItem  * item = list._first;    remove_all();        while ( tmp != NULL )    {        item = new TItem( tmp->_data );        if ( _first == NULL )            _first = item;                if ( old != NULL )            old->_next = item;        old = item;        tmp = tmp->_next;    }// while    _last = old;    _size = list._size;}    template <class T>boolTSLL<T>::is_in ( const T & elem ){    TItem * tmp = _first;    while ( tmp )    {        if (tmp->_data == elem)            return true;        tmp = tmp->_next;    }// while    return false;}///////////////////////////////////////////////////// misc.////// return size in bytes used by this object//template <class T>unsigned longTSLL<T>::byte_size () const{    return sizeof(TItem*) + sizeof(TItem*) + sizeof(unsigned int) + (_size * sizeof(TItem));}    

⌨️ 快捷键说明

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