青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

DraculaW

  C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
  19 隨筆 :: 0 文章 :: 7 評(píng)論 :: 0 Trackbacks
#ifndef _LINKEDLIST_H_

#define _LINKEDLIST_H_



#include <stdexcept>



using namespace std;



class EmptyListException : public logic_error {



public:

    EmptyListException(const string& what_arg ) throw() :

      logic_error ("Empty list exception: " + what_arg) {}}

;



template <class T>

class Node {

private:

    T data;

    Node* next;



public:

    Node(T d, Node* n = NULL) : data(d), next(n) {}

    T& getData() { return data;}

    Node*& getNext() { return next;}



};



template <class T>

class LinkedList {



protected:



    Node<T>* head; // Beginning of list

    Node<T>* tail; // End of list

    int count; // Number of nodes in list



public:



    LinkedList(void) : head(NULL), tail(NULL), count(0) {}

    LinkedList(const LinkedList<T>& src); // Copy constructor

    virtual ~LinkedList(void); // Destructor



    virtual T& front(void) {



        if (head == NULL) {

            throw EmptyListException("front()");

        }

        return head->getData();

    }

    virtual T& back(void) {

        if (tail == NULL) {

            throw EmptyListException("back()");

        }

        return tail->getData();

    }

    virtual int size(void) {

        return count;

    }

    virtual bool empty(void) {

        return count == 0;

    }



    virtual void push_front(T); // Insert element at beginning

    virtual void push_back(T); // Insert element at end

    virtual void pop_front(void); // Remove element from beginning

    virtual void pop_back(void); // Remove element from end



    virtual void dump(void); // Output contents of list

};



// Copy constructor

template <class T>

LinkedList<T>::LinkedList(const LinkedList<T>& src) :

count(0), head(NULL), tail(NULL) {



    Node<T>* current = src.head;

    while (current != NULL) {

        this->push_back(current->getData());

        current = current->getNext();

    }



}



// Destructor

template <class T>

LinkedList<T>::~LinkedList(void) {



    while (!this->empty()) {

        this->pop_front();

    }

}



// Insert an element at the beginning

template <class T>

void LinkedList<T>::push_front(T d) {



    Node<T>* new_head = new Node<T>(d, head);



    if (this->empty()) {

        head = tail = new_head;

    }

    else {

        head = new_head;

    }

    count++;

}



// Insert an element at the end

template <class T>

void LinkedList<T>::push_back(T d) {



    Node<T>* new_tail = new Node<T>(d, NULL);



    if (this->empty()) {

        head = new_tail;

    }

    else {

        tail->getNext() = new_tail;

    }



    tail = new_tail;

    count++;

}



// Remove an element from the beginning

template <class T>

void LinkedList<T>::pop_front(void) {



    if (head == NULL) {

        throw EmptyListException("pop_front()");

    }



    Node<T>* old_head = head;



    if (this->size() == 1) {

        head = NULL;

        tail = NULL;

    }

    else {

        head = head->getNext();

    }



    delete old_head;

    count--;

}



// Remove an element from the end

template <class T>

void LinkedList<T>::pop_back(void) {



    if (tail == NULL) {

        throw EmptyListException("pop_back()");

    }



    Node<T>* old_tail = tail;



    if (this->size() == 1) {

        head = NULL;

        tail = NULL;

    }

    else {



        // Traverse the list

        Node<T>* current = head;

        while (current->getNext() != tail) {

            current = current->getNext();

        }



        // Unlink and reposition

        current->getNext() = NULL;

        tail = current;

    }



    delete old_tail;

    count--;

}



// Display the contents of the list

template <class T>

void LinkedList<T>::dump(void) {



    cout << "(";



    if (head != NULL) {

        Node<T>* current = head;

        while (current->getNext() != NULL) {

            cout << current->getData() << ", ";

            current = current->getNext();

        }

        cout << current->getData();

    }



    cout << ")" << endl;

}



#endif



#ifndef _ENHANCELINKLIST_H_

#define _ENHANCELINKLIST_H_



#include "LinkedList.h"



template<typename T>

class EnhancedLinkedList: public LinkedList<T>

{

public:

    T& find_first (const T& key);

    //Method find_first should search the EnhancedLinkedList for the first

    //occurrence of an item that matches the value in the parameter key.

    //It should return a reference to the first matching item.

    //If the invoking EnhancedLinkedList object is empty or no item is found

    //that matches the parameter, a ListItemNotFoundException should be thrown.

    //You will have to define this exception

    //(Hint: define this exception much the same way that the

    //EmptyListException exception is defined in LinkedList.h).



    EnhancedLinkedList find_all (const T& key);

    //Method find_all should search the invoking EnhancedLinkedList

    //for all elements that match the value in the parameter key.

    //It should return an EnhancedLinkedList object containing

    //copies of all the items that match the parameter key.

    //If the invoking EnhancedLinkedList object is empty or

    //no item is found that matches the parameter,

    //this function should return an empty EnhancedLinkedList.



    void remove_first (const T& key);

    //Method remove_first should remove the first element from the

    //invoking EnhancedLinkedList whose data item matches the parameter key.

    //If the invoking EnhancedLinkedList object is empty or no item is found

    //that matches the parameter, this function should do nothing.

    //Remember to leave no memory leaks.



    void remove_all (const T& key);

    //Method remove_all should remove all elements from the invoking

    //EnhancedLinkedList whose data items match the parameter key.

    //If the invoking EnhancedLinkedList object is empty or no item is found

    //that matches the parameter, this function should do nothing.

    //Remember to leave no memory leaks.

};



template<typename T>

T& EnhancedLinkedList<T>::find_first(const T& key)

{

    Node<T>* temp = this->head;

    if(temp == NULL)

        throw EmptyListException("Find first emptylist");



    while(NULL != temp->getNext())

    {

        if(temp->getData()==key)

            return temp->getData();

        else

            temp=temp->getNext();

    }



    throw EmptyListException("Find first not found");

}



template<typename T>

EnhancedLinkedList<T>

EnhancedLinkedList<T>::find_all(const T& key)

{

    EnhancedLinkedList<T> resualt;



    Node<T>* temp = this->head;



    while(NULL != temp)

    {

        if(temp->getData()==key)

            resualt.push_back(temp->getData());

        temp=temp->getNext();

    }


end:
    return resualt;

}



template<typename T>

void

EnhancedLinkedList<T>::remove_first(const T& key)

{

    EnhancedLinkedList<T> list;



    while(NULL!=this->head)

    {

        if(this->head->getData()!=key)

            list.push_front(this->head->getData());

        else{

            T* temp = this->front();

            this->pop_front();

            delete temp;

            break;

        }

        this->pop_front();

    }



    while(list.head!=NULL)

    {

        this->push_front(list.front());

        list.pop_front();

    }

}



template<typename T>

void

EnhancedLinkedList<T>::remove_all(const T& key)

{

    EnhancedLinkedList<T> list;



    while(NULL!=this->head)

    {

        if(this->head->getData()!=key){

            list.push_front(this->head->getData());

            this->pop_front();

        }

        else{

            T* temp = this->front();

            this->pop_front();

            delete temp;

        }

    }



    while(list.head!=NULL)

    {

        this->push_front(list.front());

        list.pop_front();

    }

}



#endif //_ENHANCELINKLIST_H_
posted on 2007-11-15 20:29 DraculaW 閱讀(293) 評(píng)論(0)  編輯 收藏 引用

只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            麻豆免费精品视频| 国产精品高潮呻吟久久av无限| 国产精品日韩专区| 午夜精品福利一区二区蜜股av| 亚洲理论在线| 国产精品高清免费在线观看| 午夜国产一区| 午夜精品久久久久久久99水蜜桃| 一道本一区二区| 国产精品视频九色porn| 久久国产精品一区二区| 久久久久国产精品厨房| 亚洲精品国产拍免费91在线| 亚洲欧洲一区二区在线观看| 欧美jizzhd精品欧美喷水| 另类综合日韩欧美亚洲| 免费日韩一区二区| 亚洲一区亚洲| 久久大香伊蕉在人线观看热2| 亚洲电影免费观看高清完整版在线 | 午夜欧美视频| 久久国内精品自在自线400部| 亚洲黄色一区| 亚洲一区二区3| …久久精品99久久香蕉国产| 亚洲人成毛片在线播放| 国产日韩欧美精品| 亚洲国产一区二区a毛片| 亚洲精品偷拍| 国产永久精品大片wwwapp| 欧美黑人一区二区三区| 国产精品私拍pans大尺度在线| 久久久午夜精品| 欧美日韩亚洲系列| 久久在线视频| 国产精品久久久久高潮| 亚洲第一精品在线| 亚洲免费中文| 日韩视频免费在线观看| 久久精品视频免费观看| 亚洲你懂的在线视频| 久久这里只有| 久久久久久久尹人综合网亚洲 | 亚洲日本中文字幕免费在线不卡| 国产乱码精品| 亚洲精品一区二区三区不| 精久久久久久| 亚洲永久精品大片| 国产精品99久久久久久白浆小说| 欧美一区二区三区在线视频| 中文在线资源观看网站视频免费不卡| 久久久精品国产免大香伊| 亚洲欧美卡通另类91av| 欧美激情视频在线播放| 免费一级欧美片在线观看| 国产精品日韩高清| 亚洲午夜视频在线| 亚洲一区视频在线| 欧美视频官网| 99国产精品久久| 亚洲美女精品成人在线视频| 噜噜爱69成人精品| 久热精品在线视频| 1024成人| 久久久亚洲国产天美传媒修理工| 欧美专区第一页| 国产精品影音先锋| 午夜精品久久久久久99热| 亚洲专区一区| 国产老女人精品毛片久久| 亚洲图片在线观看| 国产精品久久久久久av福利软件 | 亚洲视频国产视频| 欧美日韩精品三区| 一区二区三区不卡视频在线观看| 欧美成黄导航| 亚洲国产欧美另类丝袜| 亚洲精品小视频| 欧美精品久久久久久久久老牛影院| 欧美激情区在线播放| 亚洲久久在线| 国产精品乱子乱xxxx| 国产一区二区精品久久99| 亚洲一区二区三区777| 亚洲尤物精选| 国产一区日韩一区| 久久久久久久精| 欧美激情偷拍| 亚洲一区二区成人在线观看| 国产精品激情电影| 欧美一区永久视频免费观看| 国产欧美精品| 久久久一二三| 亚洲精品乱码久久久久久久久| 中文在线不卡视频| 国产亚洲精品综合一区91| 久久视频在线看| 一本不卡影院| 久久在线免费视频| 中文久久精品| 黄色亚洲大片免费在线观看| 免费亚洲一区| 欧美一区二区三区在线观看视频| 欧美超级免费视 在线| 亚洲一级免费视频| 精品动漫3d一区二区三区免费版 | 欧美性开放视频| 久久av老司机精品网站导航| 亚洲国产高清一区| 久久久久久尹人网香蕉| 亚洲毛片在线观看.| 国内免费精品永久在线视频| 欧美激情国产精品| 久久久久9999亚洲精品| 夜夜嗨av色综合久久久综合网| 久久久久久夜精品精品免费| 一本一本久久| 在线看日韩av| 国产一区二区按摩在线观看| 欧美极品aⅴ影院| 久久精品国产亚洲一区二区| 在线亚洲国产精品网站| 欧美高清在线| 久久综合伊人77777尤物| 午夜精品网站| 亚洲视频免费在线观看| 亚洲精品久久久久久久久久久| 国产性天天综合网| 国产精品久久久久久久久| 欧美极品在线观看| 你懂的网址国产 欧美| 久久国产日本精品| 性欧美超级视频| 亚洲午夜在线观看| 日韩视频在线观看国产| 亚洲第一区在线观看| 国产自产女人91一区在线观看| 日韩视频一区二区三区在线播放| 欧美国产另类| 免费精品视频| 免费av成人在线| 久久综合免费视频影院| 久久久一区二区| 久久精品主播| 久久人人爽人人爽爽久久| 欧美在线亚洲综合一区| 欧美一区二区日韩一区二区| 这里只有精品在线播放| 中文日韩在线| 亚洲综合导航| 午夜宅男欧美| 久久成人精品无人区| 久久国产视频网站| 久久久久久尹人网香蕉| 久久久久久久网| 欧美成人免费va影院高清| 免费日韩av| 亚洲国产精品一区在线观看不卡 | 一区二区三区国产精华| 在线一区欧美| 性欧美videos另类喷潮| 久久久久久久久久久一区 | 欧美在线视频观看| 久久久久久电影| 欧美国产三区| 夜夜嗨av一区二区三区四季av| 亚洲小说欧美另类社区| 久久国产主播精品| 欧美精品久久天天躁| 国产精品第一区| 国产一区二区三区在线观看网站 | 亚洲精品视频在线观看免费| 一区二区三区av| 久久爱另类一区二区小说| 欧美~级网站不卡| 日韩亚洲精品视频| 亚洲欧美中文日韩v在线观看| 久久日韩精品| 国产精品成人观看视频免费 | 国产女同一区二区| 激情久久婷婷| 亚洲视屏一区| 麻豆成人91精品二区三区| 91久久精品www人人做人人爽 | 久久综合久久综合这里只有精品| 欧美成人精品三级在线观看| 日韩亚洲精品视频| 久久躁日日躁aaaaxxxx| 欧美性猛交视频| 亚洲大片在线观看| 翔田千里一区二区| 亚洲精品免费在线播放| 欧美一区二区在线免费观看| 欧美大片免费久久精品三p| 国产精品入口福利| 9色porny自拍视频一区二区| 久久亚洲精品中文字幕冲田杏梨| 亚洲免费播放| 欧美v亚洲v综合ⅴ国产v| 国产一区二区三区四区老人|