2#include3#include4#include5#include6#include7#inc" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Data Structure Linked List: Write a function

系統(tǒng) 2380 0

http://www.geeksforgeeks.org/write-a-function-to-get-the-intersection-point-of-two-linked-lists/

第一第二個方法比較簡單,下面這段代碼是第三個方法

      
         1
      
       #include <iostream>


      
         2
      
       #include <vector>


      
         3
      
       #include <algorithm>


      
         4
      
       #include <queue>


      
         5
      
       #include <stack>


      
         6
      
       #include <
      
        string
      
      >


      
         7
      
       #include <fstream>


      
         8
      
       #include <map>


      
         9
      
       #include <
      
        set
      
      >


      
        10
      
      
        using
      
      
        namespace
      
      
         std;


      
      
        11
      
      
        12
      
      
        struct
      
      
         node {


      
      
        13
      
      
        int
      
      
         data;


      
      
        14
      
           node *
      
        next;


      
      
        15
      
           node() : data(
      
        0
      
      
        ), next(NULL) { }


      
      
        16
      
           node(
      
        int
      
      
         d) : data(d), next(NULL) { }


      
      
        17
      
      
        };


      
      
        18
      
      
        19
      
      
        void
      
       push(node* &head, 
      
        int
      
      
         k) {


      
      
        20
      
           node *new_node = 
      
        new
      
      
         node(k);


      
      
        21
      
           new_node->next =
      
         head;


      
      
        22
      
           head =
      
         new_node;


      
      
        23
      
      
        }


      
      
        24
      
      
        25
      
      
        void
      
       print(node*
      
         head) {


      
      
        26
      
      
        while
      
      
         (head) {


      
      
        27
      
               cout << head->data << 
      
        "
      
      
        "
      
      
        ;


      
      
        28
      
               head = head->
      
        next;


      
      
        29
      
      
            }


      
      
        30
      
           cout <<
      
         endl;


      
      
        31
      
      
        }


      
      
        32
      
      
        33
      
      
        int
      
       getintersect(node *first, node *
      
        second) {


      
      
        34
      
      
        int
      
       c1 = 
      
        0
      
      
        ;


      
      
        35
      
      
        int
      
       c2 = 
      
        0
      
      
        ;


      
      
        36
      
           node *p =
      
         first;


      
      
        37
      
      
        while
      
      
         (p) {


      
      
        38
      
               c1++
      
        ;


      
      
        39
      
               p = p->
      
        next;


      
      
        40
      
      
            }


      
      
        41
      
           p =
      
         second;


      
      
        42
      
      
        while
      
      
         (p) {


      
      
        43
      
               c2++
      
        ;


      
      
        44
      
               p = p->
      
        next;


      
      
        45
      
      
            }


      
      
        46
      
      
        if
      
       (c1 <
      
         c2) {


      
      
        47
      
      
                swap(c1, c2);


      
      
        48
      
      
                swap(first, second);


      
      
        49
      
      
            }


      
      
        50
      
      
        while
      
       (c1 !=
      
         c2) {


      
      
        51
      
               c1--
      
        ;


      
      
        52
      
               first = first->
      
        next;


      
      
        53
      
      
            }


      
      
        54
      
      
        while
      
       (first !=
      
         second) {


      
      
        55
      
               first = first->
      
        next;


      
      
        56
      
               second = second->
      
        next;


      
      
        57
      
      
            }


      
      
        58
      
      
        return
      
       second->
      
        data;


      
      
        59
      
      
        }


      
      
        60
      
      
        61
      
      
        int
      
      
         main() {


      
      
        62
      
           node *head = 
      
        new
      
       node(
      
        3
      
      
        );


      
      
        63
      
           head->next = 
      
        new
      
       node(
      
        6
      
      
        );


      
      
        64
      
           head->next->next = 
      
        new
      
       node(
      
        9
      
      
        );


      
      
        65
      
           head->next->next->next = 
      
        new
      
       node(
      
        15
      
      
        );


      
      
        66
      
           head->next->next->next->next = 
      
        new
      
       node(
      
        30
      
      
        );


      
      
        67
      
           node *second = 
      
        new
      
       node(
      
        10
      
      
        );


      
      
        68
      
           second->next = head->next->next->
      
        next;


      
      
        69
      
           cout <<
      
         getintersect(head, second);


      
      
        70
      
      
        return
      
      
        0
      
      
        ;


      
      
        71
      
       }
    

?第四第五個方法不太容易想到

Data Structure Linked List: Write a function to get the intersection point of two Linked Lists.


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚州一二区 | 精品久久久在线观看 | 日本黄色网址免费 | 九九免费观看全部免费视频 | 日韩欧美在线中文字幕 | 亚洲视频高清 | 亚洲欧美字幕 | 九九热免费在线观看 | 国产高清免费 | 国产欧美精品一区二区 | 久久成人免费观看全部免费 | 亚洲黄色片视频 | 永久国产| 狠狠色噜噜狠狠米奇777 | 国产精品嫩草研究所永久网址 | 国产高清在线精品 | 亚洲欧美日韩一区超高清 | 婷婷操 | 免费看一级黄色录像 | 中文字幕 一区 婷婷 在线 | 国产目拍亚洲精品一区二区三区 | 亚洲va欧美va国产va天堂 | 老潮湿影院免费体验区 | 狠狠做狠狠做综合日日 | 一a一级片| 国产中文字幕在线免费观看 | 奇米影视777狠狠狠888不卡 | 国产女人体一区二区三区 | 视频二区欧美 | 亚洲第一综合色 | 久久久亚洲伊人色综合网站 | 91视频中文字幕 | 中国特级黄一级真人毛片 | 久操久操久操 | 久久香蕉国产线看精品 | 国产伦一区二区三区免费 | 国产精品久久久久无码av | 伊人色婷婷综在合线亚洲 | 久久九色综合九色99伊人 | 四虎comwww最新地址 | 全亚洲最大的免费私人影剧院 |