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

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 閱讀(287) 評(píng)論(0)  編輯 收藏 引用

只有注冊用戶登錄后才能發(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免费看影院| 国产精品99久久久久久久久久久久 | 国产精品稀缺呦系列在线| 欧美视频在线观看| 国产精品亚洲不卡a| 国产自产女人91一区在线观看| 黄色亚洲免费| 亚洲精品欧美精品| 在线亚洲一区观看| 久久精品在这里| 国产精品xxx在线观看www| 午夜国产不卡在线观看视频| 久久福利资源站| 欧美成人午夜免费视在线看片| 欧美激情性爽国产精品17p| 国产精品乱看| 在线成人亚洲| 亚洲与欧洲av电影| 欧美1级日本1级| 一区二区三欧美| 久久免费偷拍视频| 国产精品视频久久一区| 在线免费精品视频| 欧美一级在线播放| 91久久在线| 一区二区欧美在线观看| 久久免费偷拍视频| 国产精品久久久久天堂| 亚洲国产天堂网精品网站| 亚洲欧美日韩国产中文在线| 欧美国产日韩一区| 欧美一区二区播放| 国产精品久久久久999| 亚洲人成在线影院| 久久久亚洲影院你懂的| 中文精品视频| 欧美另类videos死尸| 伊人久久噜噜噜躁狠狠躁| 午夜亚洲精品| 亚洲视频在线观看免费| 欧美不卡在线视频| 黑人操亚洲美女惩罚| 亚欧成人在线| 亚洲午夜av在线| 欧美日韩一区自拍| 一二三四社区欧美黄| 亚洲国产成人tv| 蜜臀av性久久久久蜜臀aⅴ四虎| 国产日韩欧美综合一区| 性xx色xx综合久久久xx| 亚洲影视综合| 国产精品一区免费观看| 亚洲欧美日本另类| 亚洲网在线观看| 欧美日韩免费精品| 亚洲深夜福利在线| 一本色道久久综合亚洲精品按摩| 欧美激情aⅴ一区二区三区| 亚洲欧洲日本一区二区三区| 欧美大片91| 欧美1区2区视频| 亚洲美女视频网| 亚洲精品一区二区三区四区高清 | 亚洲电影在线| 欧美福利小视频| 免费看黄裸体一级大秀欧美| 尤物精品在线| 一区在线影院| 亚洲国产高清一区二区三区| 免费日韩精品中文字幕视频在线| 欧美一级专区免费大片| 在线观看视频亚洲| 亚洲韩国青草视频| 欧美日韩一区精品| 欧美在线亚洲综合一区| 久久久久久久999| 亚洲精品乱码久久久久久黑人| 亚洲精品一区二区网址 | 亚洲高清不卡一区| 91久久精品久久国产性色也91| 欧美精品尤物在线| 亚洲欧美国产毛片在线| 欧美有码视频| 亚洲美女淫视频| 亚洲女同同性videoxma| 影音先锋久久| aa级大片欧美三级| 国户精品久久久久久久久久久不卡 | 亚洲视频在线观看| 国产亚洲综合精品| 欧美激情导航| 国产精品日韩在线播放| 免费亚洲电影| 国产精品久久久久久妇女6080 | 亚洲尤物影院| 久久夜色撩人精品| 亚洲欧美经典视频| 久久一二三国产| 午夜精品剧场| 美女网站久久| 久久精品国内一区二区三区| 欧美高清视频一区二区三区在线观看 | 最近中文字幕mv在线一区二区三区四区| 亚洲国产精品一区二区第四页av | 亚洲娇小video精品| 国产精品夜夜嗨| 亚洲激情一区| 国外成人网址| 亚洲五月婷婷| 亚洲视频欧美视频| 另类图片国产| 久久精品成人一区二区三区蜜臀 | 欧美插天视频在线播放| 国产精品一区二区在线观看网站 | 一区二区三区国产在线观看| 一区二区三区在线视频观看| 亚洲一区二区伦理| 夜夜爽99久久国产综合精品女不卡| 久久精品国产99| 欧美在线国产| 国产精品久久久久久久久久直播 | 亚洲精品国产精品乱码不99| 狠狠88综合久久久久综合网| 亚洲欧美影音先锋| 亚洲欧美制服另类日韩| 欧美日韩性生活视频| 欧美国产亚洲精品久久久8v| 国内精品久久久久国产盗摄免费观看完整版| 99视频有精品| 亚洲欧美日韩国产| 国产麻豆日韩| 亚洲欧美美女| 久久国产精品色婷婷| 国产亚洲精品bt天堂精选| 亚洲欧美激情四射在线日 | 欧美激情影音先锋| 亚洲国产精品一区二区www| 久久久综合香蕉尹人综合网| 久久综合九色综合久99| 在线成人亚洲| 欧美ed2k| 日韩网站在线观看| 亚洲永久在线| 国产视频亚洲精品| 久久久久久欧美| 欧美高清视频在线| 99精品黄色片免费大全| 欧美性一区二区| 亚洲主播在线播放| 久久先锋影音av| 91久久精品日日躁夜夜躁国产| 欧美14一18处毛片| 一本色道久久综合| 久久久久国产一区二区三区四区 | 亚洲综合欧美日韩| 久热精品视频在线观看一区| 亚洲精一区二区三区| 欧美视频官网| 久久成人国产| 亚洲人成小说网站色在线| 亚洲——在线| 狠狠狠色丁香婷婷综合激情| 欧美成人精品一区二区三区| 日韩香蕉视频| 久久久久成人精品| 99re热精品| 国产一区二区三区的电影 | 一本色道久久综合亚洲精品按摩 | 欧美在线不卡| 亚洲国产成人高清精品| 亚洲欧美在线视频观看| 亚洲国产精品久久久久久女王| 欧美日韩一区二区高清| 欧美在线精品一区| 日韩午夜黄色| 欧美91视频| 欧美在线短视频| 亚洲视频在线观看一区| 影音先锋在线一区| 国产精品视频精品| 欧美日韩一级片在线观看| 久久国产色av| 亚洲夜晚福利在线观看| 欧美国产极速在线| 久久久噜噜噜久久狠狠50岁| 在线一区二区三区四区| 亚洲国产欧美国产综合一区| 国产精品羞羞答答| 欧美少妇一区二区| 欧美美女视频| 欧美r片在线| 久久久久久9999| 香蕉久久国产| 亚洲午夜激情在线| 亚洲最新在线视频| 欧美激情影院| 亚洲第一免费播放区| 久久一区二区三区国产精品|