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

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网站| 国产一区二区三区久久悠悠色av| 欧美三级网址| 欧美午夜宅男影院在线观看| 欧美国产日本在线| 欧美成人免费一级人片100| 久久天天躁夜夜躁狠狠躁2022| 国产色产综合产在线视频| 久久综合九色99| 欧美国产日韩xxxxx| 欧美日韩在线观看视频| 欧美亚洲免费高清在线观看| 国产亚洲欧美日韩日本| 日韩亚洲欧美一区二区三区| 欧美午夜免费影院| 99精品99久久久久久宅男| 一区二区视频免费完整版观看| 欧美视频福利| 午夜在线电影亚洲一区| 亚洲天堂av图片| 亚洲影院免费| 欧美激情免费观看| 妖精成人www高清在线观看| 中国女人久久久| 小处雏高清一区二区三区| 羞羞视频在线观看欧美| 欧美国产日本| 亚洲一区二区三区色| 欧美国产日韩一区| 一区二区三区无毛| 亚洲女爱视频在线| 亚洲国产成人av| 欧美另类极品videosbest最新版本| 欧美日韩三级视频| 亚洲最新视频在线| 亚洲日本精品国产第一区| 欧美综合77777色婷婷| 国产精品一区二区三区四区| 亚洲高清免费视频| 男同欧美伦乱| 欧美成人高清| 一本色道久久| 亚洲无线一线二线三线区别av| 欧美三级午夜理伦三级中文幕 | 国产精品美女| 亚洲一区制服诱惑| 欧美一区二区三区在| 国产模特精品视频久久久久| 中文国产一区| 久久国产精品免费一区| 亚洲国产精品福利| 亚洲另类自拍| 国产一区二区三区最好精华液| 久久理论片午夜琪琪电影网| 欧美专区日韩视频| 亚洲韩国一区二区三区| 亚洲片在线观看| 国产精品露脸自拍| 欧美电影打屁股sp| 国产精品美女久久久久av超清| 久久精品免费电影| 欧美精品大片| 欧美激情欧美狂野欧美精品| 国产精品日本| 亚洲精品久久视频| 激情文学一区| 亚洲永久免费av| 久久精品二区亚洲w码| 亚洲一区二区三区四区在线观看| 久久亚洲免费| 久久亚洲不卡| 一区二区三区在线视频观看| 亚洲一区激情| 亚洲欧美中文日韩在线| 欧美视频在线播放| 日韩一二三在线视频播| 99国产精品99久久久久久粉嫩| 久久久九九九九| 老司机午夜精品| 加勒比av一区二区| 巨乳诱惑日韩免费av| 欧美高清不卡| 一区二区av在线| 国产精品久久久久91| 亚洲宅男天堂在线观看无病毒| 亚洲欧美制服中文字幕| 黄色成人在线网址| 欧美jizzhd精品欧美喷水 | 国产精品永久| 久久亚洲捆绑美女| 日韩亚洲精品电影| 久久久久久国产精品一区| 一色屋精品视频免费看| 欧美极品影院| 午夜日韩激情| 亚洲精品一二三区| 亚洲影院免费| 亚洲精品久久久一区二区三区| 国产精品第十页| 快she精品国产999| 亚洲视频精选| 亚洲精品乱码久久久久久久久| 国产精品日韩在线| 欧美成人中文| 亚洲日本va午夜在线影院| 久久精品国产精品| 一区二区三区国产精品| 在线观看欧美亚洲| 国模精品一区二区三区| 国产精品久久久久高潮| 欧美日韩国产综合久久| 久久久一本精品99久久精品66| 亚洲视频碰碰| 亚洲一区激情| 亚洲欧美日本国产有色| 亚洲视频欧美在线| 亚洲素人一区二区| 亚洲一区欧美二区| 亚洲午夜在线观看视频在线| 91久久精品一区| 亚洲看片网站| 中文在线不卡视频| 亚洲欧美成人网| 久久免费的精品国产v∧| 欧美在线视频一区二区三区| 欧美亚洲三区| 国产精品久久久久99| 亚洲欧洲一区二区三区| 99成人在线| 欧美精品18+| 亚洲午夜久久久久久久久电影网| 激情欧美丁香| 麻豆精品精品国产自在97香蕉| 亚洲三级影院| 欧美一区二区三区在线播放| 亚洲国产精品一区二区第一页| 国产精品美女一区二区在线观看| 欧美中文字幕第一页| 亚洲国产日韩欧美在线99| 亚洲少妇中出一区| 亚洲一区区二区| 亚洲成色最大综合在线| 国产精品麻豆成人av电影艾秋 | 亚洲香蕉在线观看| 久久国产视频网站| 亚洲每日在线| 鲁鲁狠狠狠7777一区二区| 国产精品久久久久久久久久免费 | 国产欧亚日韩视频| 亚洲精品影院| 久久国产精品久久国产精品| 欧美一区二区免费视频| 亚洲国产精品va在看黑人| 亚洲综合视频一区| 欧美日韩国产一区| 亚洲人成毛片在线播放| 久久免费国产精品| 亚洲在线视频免费观看| 国产精品99免费看| 亚洲一区二区三区国产| 亚洲色图在线视频| 国产欧美日韩不卡免费| 久久精品官网| 久久狠狠久久综合桃花| 黄色免费成人| 亚洲国产成人av| 欧美视频在线不卡| 久久久www成人免费无遮挡大片| 亚洲欧美日本国产专区一区| 国产精品女主播| 久久精品国产一区二区电影| 久久夜色精品国产噜噜av| 亚洲人成网站色ww在线| 亚洲激情在线观看| 欧美调教vk| 美女视频一区免费观看| 欧美日韩免费一区| 久久久久国色av免费看影院| 美腿丝袜亚洲色图| 午夜在线电影亚洲一区| 免费观看成人www动漫视频| 一片黄亚洲嫩模| 亚洲在线播放电影| 欧美一级视频一区二区| 亚洲人成网站在线观看播放| 亚洲精品视频免费在线观看| 国产色婷婷国产综合在线理论片a| 欧美成年人视频网站| 国产日韩亚洲欧美精品| 日韩午夜黄色| 99国内精品久久| 久久伊伊香蕉| 欧美激情偷拍| 亚洲国产精品电影| 免费不卡在线观看av| 久久中文精品|