• <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| www.久久热| 72种姿势欧美久久久久大黄蕉 | 久久免费视频观看| 久久偷看各类wc女厕嘘嘘 | 国产亚洲欧美成人久久片| 久久久久久久女国产乱让韩| 久久成人精品| 精品无码人妻久久久久久| 久久国产精品久久| 久久99精品国产麻豆宅宅| 久久国产亚洲精品无码| 亚洲精品国产字幕久久不卡| 蜜桃麻豆WWW久久囤产精品| 久久夜色撩人精品国产| 日韩电影久久久被窝网| 久久影院午夜理论片无码| 久久久久国色AV免费观看| 青青青国产成人久久111网站| 91精品国产色综合久久| 国产精品久久波多野结衣| 国产精品久久国产精品99盘 | 久久亚洲2019中文字幕| 免费一级欧美大片久久网 | 亚洲欧洲精品成人久久曰影片| 久久婷婷五月综合97色直播|