前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >js实现图的构造

js实现图的构造

作者头像
theanarkh
发布2019-03-06 10:58:59
2K0
发布2019-03-06 10:58:59
举报
文章被收录于专栏:原创分享原创分享
代码语言:javascript
复制
function Edge(data) {
        this.src = data[0];
        this.des = data[1];
        this.weight = data[2];
        this.next = null;
    }

    function Node(val) {
        this.val = val;
        this.next = null;
    }
    var graph = {};

    function makeGraph() {
        var data = [[0,1,2],[1,2,3],[3,4,11],[2,4,21],[4,3,12],[4,5,111]];
        for (var i = 0; i < data.length; i++) {
            var current = data[i];
            var edge = new Edge(current);
            if (graph[current[0]]) {
                edge.next = graph[current[0]].next;
                graph[current[0]].next = edge;
            } else {
                graph[current[0]] = new Node(current[0]);
                graph[current[0]].next = edge;
                edge.next = null;
            }
        }
    }
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-02-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 编程杂技 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档