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

            單鏈表的翻轉

            非常簡單的實現,設置3個指針,分別指向當前節點、前一個節點、后一個節點,然后依次處理所有的節點就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)  編輯 收藏 引用

            My Links

            Blog Stats

            常用鏈接

            留言簿(1)

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            成人久久久观看免费毛片| 欧美激情精品久久久久久久| 国产精品日韩深夜福利久久 | 久久精品久久久久观看99水蜜桃| 久久天天躁狠狠躁夜夜avapp| 久久久久久久精品妇女99| 久久亚洲AV成人无码国产| 国产精品熟女福利久久AV| 伊人久久一区二区三区无码| 欧美777精品久久久久网| 久久久久久精品免费看SSS| 欧美黑人又粗又大久久久| 丰满少妇人妻久久久久久4| 亚洲日本久久久午夜精品| 99热成人精品热久久669| 久久精品夜色噜噜亚洲A∨| 麻豆成人久久精品二区三区免费| 青青青国产成人久久111网站| 狠狠色丁香久久婷婷综合图片| 久久99精品久久久久久9蜜桃| 久久夜色精品国产亚洲| 亚洲美日韩Av中文字幕无码久久久妻妇 | 激情伊人五月天久久综合| 久久妇女高潮几次MBA| 99久久国产免费福利| 精品久久香蕉国产线看观看亚洲| 国内精品九九久久精品| 精品久久久无码21p发布| 精品99久久aaa一级毛片| 99re久久精品国产首页2020| 久久精品国产欧美日韩99热| 国内精品免费久久影院| 97久久综合精品久久久综合| 色8久久人人97超碰香蕉987| 人妻少妇久久中文字幕| 亚洲日韩中文无码久久| 久久婷婷五月综合成人D啪| 久久综合九色综合欧美就去吻| 国产99久久久国产精免费| 久久久91精品国产一区二区三区| 国产精品美女久久久m|