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

            單鏈表的翻轉(zhuǎn)

            非常簡單的實現(xiàn),設(shè)置3個指針,分別指向當(dāng)前節(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 閱讀(2026) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            My Links

            Blog Stats

            常用鏈接

            留言簿(1)

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久亚洲2019中文字幕| 久久精品成人影院| 久久九九全国免费| 色悠久久久久久久综合网| 色偷偷88欧美精品久久久| 精品人妻久久久久久888| 久久99精品国产99久久6| 无码专区久久综合久中文字幕| 国产精品久久亚洲不卡动漫| 欧美麻豆久久久久久中文| 99久久精品午夜一区二区| 欧美成人免费观看久久| 久久久久综合网久久| 久久久久久久久无码精品亚洲日韩| 国内精品久久久久久久coent| 亚洲午夜无码久久久久| 久久se精品一区二区影院| 99久久无色码中文字幕| 久久无码高潮喷水| 久久久久久青草大香综合精品| 无码超乳爆乳中文字幕久久| 欧美亚洲国产精品久久久久| 精品国产一区二区三区久久蜜臀| 久久精品国产亚洲精品2020| 伊色综合久久之综合久久| 久久精品国产亚洲精品| 国产高潮国产高潮久久久91| 狠狠88综合久久久久综合网| 18岁日韩内射颜射午夜久久成人| 久久久久97国产精华液好用吗| 久久国产精品99精品国产987| 日韩精品久久久久久免费| 中文精品99久久国产| 怡红院日本一道日本久久 | 人妻丰满?V无码久久不卡| 热re99久久精品国99热| 中文无码久久精品| 亚洲国产精品久久电影欧美| 久久影院综合精品| 久久久久亚洲精品无码蜜桃| 午夜精品久久久久久毛片|