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

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Data Structure Linked List: Write a function

系統(tǒng) 2120 0

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

第一第二個(gè)方法比較簡(jiǎn)單,下面這段代碼是第三個(gè)方法

      
         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
      
       }
    

?第四第五個(gè)方法不太容易想到

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


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

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

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

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 成人精品一区 | 天天干天天色综合 | 亚洲精品乱码8久久久久久日本 | 不卡一区二区三区四区 | 五月丁香综合啪啪成人小说 | 搜一级毛片 | 亚洲精品人成网在线播放影院 | 日韩精品一区二 | 一级毛片不卡片免费观看 | 久久精品一区二区免费播放 | 一级毛片视频免费 | 无遮挡羞羞视频 | 色婷婷久久免费网站 | 日韩欧美在线观看视频一区二区 | 99精品国产高清在线观看 | 麻豆国产 | www.99热这里只有精品 | 欧美日韩久久 | 欧美成人xxxx | 性夜影院爽黄e爽在线观看 苏晓晖个人简介军衔 | 欧美视频亚洲视频 | 久久精品国产一区二区 | 99re6在线视频精品免费 | 亚洲伦理影院 | 91免费无限观看 | 国产无线乱码一区二三区 | 精品国产AV色一区二区深夜久久 | 成人黄色一级视频 | 五月天91 | 国产在线第一页 | 一道本视频在线观看 | 国产成人精品一区二区三在线观看 | 成人性视频免费网站 | 国产日韩精品一区 | 久久精品99久久 | 国内精品免费视频 | 噜噜狠狠 | 一级片在线视频 | 日韩高清一区二区 | 日韩精品一区二区三区在线观看 | 91你懂的|