zoukankan      html  css  js  c++  java
  •     //图
        function Graph(v) {
            this.vertices = v;
            this.vertextlist = [];
            this.edges = 0;
            this.adj = [];
            for (var i = 0; i < this.vertices; ++i) {
                this.adj[i] = [];
                this.adj[i]="";
            }
            this.addEdge = addEdge;
            this.showGraph = showGraph;
            this.dfs = dfs;
            this.marked = [];
            for (var i = 0; i < this.vertices; i++) {
                this.marked[i] = false;
            }
            this.bfs = bfs;
            this.edgeTo = [];
            this.hasPathTo = hasPathTo;
            this.topSortHelper = topSortHelper;
            this.topSort = topSort;
        }
     
        function topSort() {
            var stack = [];
            var visited = [];
            for (var i = 0; i < this.vertices; i++) {
                visited[i] = false;
            }
            for (var i = 0; i < stack.length; i++) {
                if (visited[i] = false) {
                    this.topSortHelper(i, visited, stack);
                }
            }
            for (var i = 0; i < stack.length; i++) {
                if (stack[i] != undefined && stack[i] != false) {
                    print(this.vertextlist[stack[i]]);
                }
            }
        }
     
        function topSortHelper(v,visited,stack) {
            visited[v] = true;
            for (var i = 0; i < this.adj[v].length;i++)
            {
                if (!visited[i]) {
                    this.topSortHelper(visited[i], visited, stack);
                }
            }
            stack.push(v);
        }
     
        function addEdge(v,w) {
            this.adj[v]=w;
            this.adj[w]=v;
            this.edges++;
        }
     
       
        function showGraph() {
            for (var i = 0; i < this.vertices; i++) {
                for (var j = 0; j < this.vertices; ++j) {
                    if (this.adj[i][j] != undefined)
                    {
                        document.getElementById('Context').innerHTML = this.adj[i][j];
                    }
                }
            }
        }
     
        var dataStore = [];
        var nums = 100;
        function setData() {
            for (var i = 0; i <nums; i++) {
                dataStore[i] = Math.floor(Math.random() * (nums + 1));
            }
        }
     
        function ToString() {
            var restr = "";
            for (var i = 0; i < dataStore.length; i++) {
                restr += dataStore[i] + " ";
                if (i > 0 && i % 10 == 0)
                {
                    restr += "</br>";
                }
            }
        //    return restr;
        //}
    好好学习,天天向上。
  • 相关阅读:
    Insus Meta Utility
    The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
    Insus Binary Utility
    asp.net实现文件下载功能
    Column 'Column Name' does not belong to table Table
    程序已被编译为DLL,怎样去修改程序功能
    如何在Web网站实现搜索功能
    如何把数据流转换为二进制字符串
    Asp.net更新文件夹的文件
    如何显示中文月份
  • 原文地址:https://www.cnblogs.com/Zhengxue/p/6141421.html
Copyright © 2011-2022 走看看