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

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲?V乱码久久精品蜜桃| 一本色道久久88精品综合| 久久成人国产精品免费软件| 色偷偷88欧美精品久久久| 亚洲精品无码久久久久久| 99久久国产综合精品麻豆| 久久97久久97精品免视看| 久久九九兔免费精品6| 久久精品国产91久久综合麻豆自制| 久久久久国产日韩精品网站| 亚洲AV无码久久精品狠狠爱浪潮| 久久被窝电影亚洲爽爽爽| 久久久www免费人成精品| 久久99久久99小草精品免视看 | 亚洲国产精品无码成人片久久| 久久久精品一区二区三区| 色天使久久综合网天天| 精品无码久久久久久久动漫| 久久婷婷五月综合97色一本一本 | 欧美精品一本久久男人的天堂 | 国产精品久久精品| 久久综合九色综合网站| 久久国产成人午夜AV影院| 国产精品视频久久久| 色欲久久久天天天综合网精品| 四虎影视久久久免费| 久久se精品一区精品二区国产| 2021久久国自产拍精品| 久久久精品人妻一区二区三区四| 国产精品成人久久久| 伊人精品久久久久7777| 亚洲欧美日韩精品久久亚洲区| 久久免费香蕉视频| 久久久久免费视频| 久久最新免费视频| 久久91这里精品国产2020| 久久国产精品免费一区二区三区| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久国产香蕉一区精品| 国产91久久精品一区二区| 人妻无码中文久久久久专区 |