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

DraculaW

  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
  19 隨筆 :: 0 文章 :: 7 評論 :: 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 閱讀(289) 評論(0)  編輯 收藏 引用

只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   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视频+国产日韩欧美| 日韩午夜激情| 久久久久久久999精品视频| 一区二区三区毛片| 亚洲精品自在在线观看| 国产精品一区免费在线观看| 国产精品国产三级国产专播品爱网| 欧美午夜电影完整版| 国产精品视频一区二区三区| 国产丝袜美腿一区二区三区| 在线电影国产精品| aa级大片欧美三级| 欧美一区视频| 久久久综合网站| 欧美二区乱c少妇| 亚洲国产精品ⅴa在线观看| 美国十次了思思久久精品导航| 欧美激情精品久久久久久免费印度| 亚洲人成绝费网站色www| 一本色道久久综合亚洲精品不| 亚洲一区二区视频| 久久久国产精品亚洲一区 | 亚洲电影在线| 一区二区三区回区在观看免费视频| 亚洲一区免费在线观看| 美日韩在线观看| 一区二区三区久久久| 久久天天狠狠| 欧美激情影院| 欧美精品久久久久久久免费观看 | 久久久精品日韩| 免费日韩av| 国产精品美女主播| 在线免费日韩片| 亚洲欧美精品伊人久久| 欧美国产三区| 欧美中在线观看| 国产精品欧美久久| 99精品欧美| 可以看av的网站久久看| 亚洲一二三区在线| 欧美精品入口| 亚洲人成77777在线观看网| 欧美在线综合视频| 99re6这里只有精品| 欧美高清视频一区| 1000部国产精品成人观看| 欧美一区二区女人| 亚洲靠逼com| 欧美精品一区三区在线观看| 伊人久久噜噜噜躁狠狠躁| 亚洲午夜电影在线观看| 亚洲国产精品一区二区www在线| 久久久福利视频| 国产日韩欧美在线观看| 欧美一区=区| 亚洲女人天堂av| 欧美日韩伦理在线| 日韩网站免费观看| 亚洲高清三级视频| 免费亚洲婷婷| 一区二区三区在线免费观看| 欧美中文字幕不卡| aa成人免费视频| 欧美a级片网站| 在线观看日产精品| 欧美成人综合一区| 美女免费视频一区| 亚洲国产毛片完整版| 蜜臀a∨国产成人精品| 久久久久国产精品www| 国产欧美一区二区精品婷婷| 久久久精品免费视频| 久久久97精品| 亚洲国产成人不卡| 亚洲国产欧美日韩另类综合| 欧美日本在线| 午夜精品理论片| 欧美一区在线直播| 91久久久久久| 中文精品99久久国产香蕉| 国产精品一区=区| 影音先锋欧美精品| 亚洲狼人综合| 亚洲图中文字幕| 国内伊人久久久久久网站视频| 另类亚洲自拍| 欧美揉bbbbb揉bbbbb| 久久精品国产欧美亚洲人人爽| 久久午夜国产精品| 中日韩午夜理伦电影免费| 午夜视频一区| 亚洲高清视频一区二区| 亚洲乱码久久| 亚洲国产成人午夜在线一区| 亚洲精一区二区三区| 久久成人亚洲| 免费不卡在线观看av| 亚洲一区免费| 玖玖综合伊人| 性8sex亚洲区入口| 麻豆成人综合网| 亚洲欧美国产不卡| 久久久久久综合| 亚洲欧美日韩一区二区在线| 久久aⅴ乱码一区二区三区| av成人免费在线| 久久精品国产综合精品| 亚洲在线成人精品| 欧美好骚综合网| 久久亚洲精品一区| 欧美日韩在线三级| 亚洲成色777777女色窝| 国产精品一区二区a| 亚洲精品国产欧美| 亚洲国产mv| 久久久国产精品一区| 销魂美女一区二区三区视频在线| 美女精品在线| 女主播福利一区| 狠狠色丁香婷婷综合久久片| 妖精视频成人观看www| 亚洲国产精品高清久久久| 亚洲欧美大片| 亚洲一区二区免费视频| 欧美精品www在线观看| 嫩草成人www欧美| 今天的高清视频免费播放成人 | 亚洲天堂av图片| 99国内精品| 欧美老女人xx| 亚洲韩国精品一区| 亚洲国产欧美一区| 久久先锋资源| 免费成人毛片| 亚洲国产综合91精品麻豆| 久久久美女艺术照精彩视频福利播放| 久久国产黑丝| 国产亚洲制服色| 欧美在线免费观看视频| 久久国产精品久久国产精品| 国产亚洲精品美女| 久久国产精品72免费观看| 久久久久综合网| 在线免费高清一区二区三区| 久久综合99re88久久爱| 欧美sm重口味系列视频在线观看| 欧美在线观看网址综合| 国产精品日韩高清| 午夜免费久久久久| 久久综合一区二区三区| 亚洲黄色免费| 欧美日韩国产欧| 在线亚洲激情| 久久男人av资源网站| 亚洲国产精品一区二区尤物区| 欧美高清视频一二三区| 亚洲视频网在线直播| 久久精品免费| 亚洲精品四区| 国产精品一二三四区| 久久亚洲视频| 一区二区av在线| 久久天堂成人| 一二三区精品| 国模套图日韩精品一区二区| 久久综合色播五月| 亚洲午夜极品| 欧美高清视频| 西瓜成人精品人成网站| 在线观看国产一区二区| 欧美日韩一区在线视频| 欧美一区二区三区免费视| 91久久精品一区二区别| 久久xxxx| 亚洲一二三四区| 尹人成人综合网| 国产精品啊v在线| 久久久综合网站| 亚洲视频中文字幕| 男人的天堂亚洲| 欧美亚洲视频一区二区| 亚洲国产日韩在线一区模特| 国产精品久久久久免费a∨| 久久综合九色九九| 亚洲综合精品四区| 亚洲国产综合在线| 久久亚裔精品欧美| 性做久久久久久免费观看欧美| 亚洲黄色一区| 国产综合精品| 国产精品系列在线播放| 欧美日韩福利| 欧美不卡高清| 久久视频在线视频| 久久国产直播|