• <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>

            Problem Solving using C++

            Algorithm Study using C++

            單鏈表的翻轉

            非常簡單的實現(xiàn),設置3個指針,分別指向當前節(jié)點、前一個節(jié)點、后一個節(jié)點,然后依次處理所有的節(jié)點就OK了。
            具體代碼為:
            #include <iostream>

            using namespace std;

            #ifndef 
            null
            #define 
            null (void*)0
            #endif

            typedef struct node
            {
                struct node
            * next;
                
            int data;
            }node;

            node
            * head=(node*)null;

            void reverse(node* root)
            {
                node 
            *cur,*pre,*next;
                
                pre
            =(node*)null;
                cur
            =root;
                next
            =cur->next;
                
                
            while(next)
                {
                    cur
            ->next=pre;
                    pre
            =cur;
                    cur
            =next;
                    next
            =cur->next;
                }
                
                head
            =cur;
                cur
            ->next=pre;
            }

            void insert(node* p)
            {
                p
            ->next=head;
                head
            =p;
            }

            void del(node* p)
            {
                node 
            *cur,*next;
                cur
            =p;
                next
            =p->next;
                
                
            while(next)
                {
                    delete cur;
                    cur
            =next;
                    next
            =cur->next;
                }
                
                delete cur;
            }

            void print(node* p)
            {
                
            while(p)
                {
                    cout
            <<p->data<<" ";
                    p
            =p->next;
                }
                
                cout
            <<endl;
            }

            int main(int argc,char** argv)
            {
                
            for(int i=0;i<10;i++)
                {
                    node
            * p=new node;
                    p
            ->next=(node*)null;
                    p
            ->data=i;
                    
                    insert(p);
                }
                print(head);
                cout
            <<"reverse order:"<<endl;
                
                reverse(head);
                print(head);
                
                del(head);
                
                
                system(
            "pause");
                
            return 0;
            }


            posted on 2007-09-05 14:41 Kingoal Lee's Alogrithm Study using cplusplus 閱讀(2027) 評論(0)  編輯 收藏 引用

            My Links

            Blog Stats

            常用鏈接

            留言簿(1)

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            色偷偷久久一区二区三区| 国产成年无码久久久久毛片| 国内精品伊人久久久久av一坑 | 亚洲成av人片不卡无码久久| 久久99久久成人免费播放| 久久久国产精华液| 人妻精品久久无码专区精东影业| 久久人与动人物a级毛片| 99久久无色码中文字幕人妻| 久久国产精品久久精品国产| 色综合久久中文字幕综合网| 久久婷婷色香五月综合激情| 国产精品无码久久久久久| 国产精品综合久久第一页 | 久久精品国产只有精品66| 国产精品久久久久久久久软件| 久久精品九九亚洲精品天堂| 久久久久这里只有精品 | 精品久久久久久久中文字幕 | 99久久免费国产精品| 久久丫精品国产亚洲av| 国产成人精品久久亚洲高清不卡| 久久伊人影视| 99久久婷婷国产一区二区| 丁香色欲久久久久久综合网| 久久精品无码免费不卡| 韩国三级大全久久网站| 伊人久久大香线蕉亚洲| 97精品伊人久久久大香线蕉| 国产成人无码精品久久久性色| a级毛片无码兔费真人久久| 久久国产精品一国产精品金尊| 亚洲中文精品久久久久久不卡| 精品国产一区二区三区久久蜜臀| 久久久一本精品99久久精品66| 久久综合亚洲色一区二区三区| 久久精品国产72国产精福利| 久久最新精品国产| 国产巨作麻豆欧美亚洲综合久久| 精品无码久久久久久尤物| 亚洲欧美日韩中文久久|