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

            大漠落日

            while(!dead) study++;
            posts - 46, comments - 126, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
            /***********************************
            *    單向鏈表逆序
            *    yanzh 2011-6-23
            ***********************************
            */
            #include 
            <iostream>

            using namespace std;

            class Node{
            public:
                Node(
            int v):value(v),next(NULL){}
                
            int value;
                Node
            * next;
            };

            Node
            * init_list(int n)
            {
                Node 
            *head, *node, *tail;
                
                head 
            = tail = NULL;
                
            for (int i = 0; i < n; i++)
                {
                    node 
            = new Node(i);

                    
            if (i == 0)
                    {
                        head 
            = node;
                        tail 
            = node;
                    }
                    
            else
                    {
                        tail
            ->next = node;
                        tail 
            = node;
                    }
                }
                
            return head;
            }

            void uninit_list(Node *head)
            {
                Node 
            *node = head;
                
            while (head != NULL)
                {
                    node 
            = node->next;
                    delete head;
                    head 
            = node;
                }
                head 
            = NULL;
            }

            void reverse_list(Node **list)
            {
                Node 
            *head, *tail, *mid;

                head 
            = *list;

                
            //一個(gè)節(jié)點(diǎn),直接返回
                if (head->next == NULL)
                    
            return;

                
            //兩個(gè)節(jié)點(diǎn)或以上節(jié)點(diǎn)
                mid = head->next;
                head
            ->next = NULL;
                tail 
            = mid->next;

                
            while (tail != NULL)
                {
                    mid
            ->next = head;
                    head 
            = mid;
                    mid 
            = tail;
                    tail 
            = tail->next;
                }

                mid
            ->next = head;
                
            *list = mid;
            }

            void output(Node *list)
            {
                
            int i = 0;
                Node 
            *node = list;

                
            while (node != NULL)
                {
                    cout
            <<"node["<<i++<<"] = "<<node->value<<endl;
                    node 
            = node->next;
                }
            }

            int main(int argc, char *argv[])
            {
                
            int len = 5;
                Node 
            *list = NULL;

                
            if (argc > 1)
                    len 
            = atoi(argv[1]);
                
                list 
            = init_list(len);
                output(list);

                reverse_list(
            &list);

                
            //輸出
                cout<<"\n逆序后\n"<<endl;
                output(list);

                uninit_list(list);
                
                
            return 0;    
            }
            伊色综合久久之综合久久| 久久精品9988| 久久天天躁狠狠躁夜夜躁2014| 国产精品乱码久久久久久软件| 亚洲综合日韩久久成人AV| 久久精品国产影库免费看| 性做久久久久久久久久久| 亚洲av伊人久久综合密臀性色| 久久免费国产精品一区二区| 久久久久99精品成人片三人毛片| 国产成人久久精品一区二区三区| 久久99中文字幕久久| 久久人与动人物a级毛片| 天堂久久天堂AV色综合| 久久久久人妻一区精品| 久久香蕉国产线看观看精品yw| 久久99亚洲综合精品首页| 99久久无色码中文字幕人妻| 办公室久久精品| 丰满少妇人妻久久久久久| 亚洲国产成人久久精品99| 久久精品国产精品国产精品污| 亚洲va久久久久| 久久久久亚洲AV无码专区网站| 久久亚洲春色中文字幕久久久| 性做久久久久久久久老女人| 国产91久久综合| 国产精品99久久精品| 亚洲AV无码久久精品成人| 亚洲精品午夜国产va久久| 看全色黄大色大片免费久久久| 91精品日韩人妻无码久久不卡| 国产99久久精品一区二区| 亚洲人成伊人成综合网久久久| 久久国产AVJUST麻豆| 国産精品久久久久久久| 亚洲天堂久久精品| 国内精品免费久久影院| 久久国产精品偷99| 国产精自产拍久久久久久蜜| 久久九九久精品国产|