• <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>
            隨筆 - 8  文章 - 26  trackbacks - 0
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(5)

            隨筆檔案

            文章分類

            文章檔案

            相冊

            C++語言

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            1
              1#ifndef LIST_H
              2#define LIST_H
              3#include <iostream>
              4//鏈表節(jié)點
              5template<class T>
              6class ListNode
              7{
              8public:
              9    ListNode(ListNode<T>* nextnode=0,const T &val=T())
             10    {
             11    data=val;
             12    next=nextnode;
             13    }

             14public:
             15T data;
             16    ListNode<T> *next;
             17
             18}
            ;
             19
             20//鏈表實現(xiàn)
             21template<class T>
             22class List
             23{
             24
             25public:
             26    List();
             27    virtual ~List();
             28    void Insert_Front(const T &e);//向表頭插入節(jié)點
             29    void Insert_End(const T &e);//向表尾插入節(jié)點
             30    ListNode<T>* Find(const T &e);//查找指定節(jié)點
             31    bool Delete(const T &e);//刪除指定節(jié)點
             32    List<T>& Delete_All();//刪除除了頭結點以外的所有節(jié)點
             33    bool IsEmpty();//測試鏈表是否為空
             34    bool Size() const {return size;}//返回鏈表中的節(jié)點數(shù)目
             35    void OutPut();
             36
             37private:
             38    ListNode<T>*front,*rear,*head;//頭指針與尾指針
             39    int size;//鏈表元素節(jié)點數(shù)目
             40}
            ;
             41
             42
             43
             44
             45//---------------------------------------------------------------------
             46template<class T>
             47List<T>::~List()
             48{
             49Delete_All();
             50delete head;
             51
             52}

             53//---------------------------------------------------------------------
             54template<class T>
             55List<T>::List()
             56{
             57//構造頭接點
             58head=new ListNode<T>();
             59front=rear=head;
             60head->next=head;
             61}

             62
             63//---------------------------------------------------------------------
             64template<class T>
             65void List<T>::Insert_Front(const T &e)
             66{
             67    ListNode<T> *NewNode=new ListNode<T>(0,e);
             68if(front->next==head)//如果鏈表為空
             69{
             70
             71front->next=NewNode;
             72NewNode->next=head;
             73rear=NewNode;
             74}

             75else//鏈表不為空
             76{
             77NewNode->next=front->next;
             78front->next=NewNode;
             79}

             80++size;
             81}

             82//---------------------------------------------------------------------
             83template<class T>
             84void List<T>::Insert_End(const T &e)
             85{
             86    ListNode<T> *NewNode=new ListNode<T>(0,e);
             87if(front->next==head)//如果鏈表為空
             88{
             89
             90front->next=NewNode;
             91NewNode->next=head;
             92rear=NewNode;
             93}

             94else//鏈表不為空
             95{
             96rear->next=NewNode;
             97NewNode->next=head;
             98rear=NewNode;
             99
            100}

            101++size;
            102}

            103//---------------------------------------------------------------------
            104template<class T>
            105ListNode<T>* List<T>::Find(const T &e)
            106{
            107head->data=e;
            108ListNode<T> *move=front->next;
            109while(move->data!=e)
            110{
            111move=move->next;
            112}

            113
            114if(move==front) return NULL;
            115else
            116return move;
            117}

            118
            119//---------------------------------------------------------------------
            120template<class T>
            121bool List<T>::Delete(const T &e)
            122{
            123head->data=e;
            124ListNode<T> *move=front->next;
            125ListNode<T> *pmove=head;
            126while(move->data!=e)
            127{
            128    pmove=move;
            129move=move->next;
            130}

            131if(move==head) return false;//未找到節(jié)點
            132pmove->next=move->next;
            133if(move==rear)//如果為尾節(jié)點則修改尾指針
            134rear=pmove;
            135delete move;
            136return true;
            137}

            138
            139//---------------------------------------------------------------------
            140template<class T>
            141void List<T>::OutPut()
            142{
            143ListNode<T> *move=front->next;
            144while(move!=head)
            145{
            146cout<<move->data<<" ";
            147move=move->next;
            148}

            149cout<<endl;
            150}

            151//---------------------------------------------------------------------
            152template<class T>
            153List<T>& List<T>::Delete_All()
            154{
            155ListNode<T> *movenext,*move=front->next;
            156
            157while(move!=head)
            158{
            159movenext=move->next;
            160delete move;
            161move=movenext;
            162}

            163front=rear=head;
            164head->next=head;
            165
            166return *this;
            167}

            168//---------------------------------------------------------------------
            169template<class T>
            170bool List<T>::IsEmpty()
            171{
            172
            173if(head->next=head) return true;
            174else 
            175return false;
            176}

            177#endif
            posted on 2008-09-18 20:54 楊彬彬 閱讀(1744) 評論(0)  編輯 收藏 引用 所屬分類: 數(shù)據(jù)結構
            久久ZYZ资源站无码中文动漫| AAA级久久久精品无码区| 色8激情欧美成人久久综合电| 久久精品综合网| 无码人妻久久一区二区三区免费丨| 久久99国内精品自在现线| 国产亚洲欧美成人久久片| 亚洲?V乱码久久精品蜜桃| 国产精品久久久久国产A级| 精品久久久无码中文字幕| 亚洲国产美女精品久久久久∴| 国产午夜精品理论片久久| 久久久SS麻豆欧美国产日韩| 亚洲国产天堂久久综合网站| 天天躁日日躁狠狠久久| 色婷婷综合久久久久中文字幕| 久久精品国产网红主播| 伊人久久大香线蕉精品不卡 | 久久久久久一区国产精品| 久久影院综合精品| 日韩欧美亚洲国产精品字幕久久久 | 久久久精品日本一区二区三区| 亚洲午夜久久久久久久久电影网 | 狠狠色丁香久久婷婷综合五月| 欧美色综合久久久久久| 嫩草影院久久国产精品| 国内精品久久久久影院日本| 久久人人爽人人爽人人爽| 久久这里只精品99re66| 精品久久久久久无码人妻热 | 日本加勒比久久精品| 久久久九九有精品国产| 99re这里只有精品热久久| 精品免费久久久久久久| 久久综合88熟人妻| 国产成人久久激情91| 精品久久久久久久久中文字幕| 国产精品久久久久久久| 久久噜噜电影你懂的| 中文字幕久久欲求不满| 国产99久久久国产精品~~牛|