-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs__algorithm__datasources__chart.md.js
More file actions
1 lines (1 loc) · 6.36 KB
/
docs__algorithm__datasources__chart.md.js
File metadata and controls
1 lines (1 loc) · 6.36 KB
1
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([[4],{WyVi:function(n,e,t){"use strict";t.r(e);var a=t("q1tI"),r=t.n(a),s=t("dEAq"),l=t("H1Ra"),i=r.a.memo((n=>{n.demos;return r.a.createElement(r.a.Fragment,null,r.a.createElement("div",{className:"markdown"},r.a.createElement("h2",{id:"\u56fe\u7684\u6982\u5ff5"},r.a.createElement(s["AnchorLink"],{to:"#\u56fe\u7684\u6982\u5ff5","aria-hidden":"true",tabIndex:-1},r.a.createElement("span",{className:"icon icon-link"})),"\u56fe\u7684\u6982\u5ff5"),r.a.createElement("ul",null,r.a.createElement("li",null,r.a.createElement("p",null,"\u56fe\u7531\u8fb9\u7684\u96c6\u5408\u53ca\u9876\u70b9\u7684\u96c6\u5408\u7ec4\u6210\uff0c\u6bcf\u4e00\u4e2a\u57ce\u5e02\u5c31\u662f\u4e00\u4e2a\u9876\u70b9\uff0c\u6bcf\u4e00\u4e2a\u9053\u8def\u5c31\u662f\u4e00\u4e2a\u8fb9")),r.a.createElement("li",null,r.a.createElement("p",null,"\u9876\u70b9\u4e5f\u6709\u6743\u91cd\uff0c\u4e5f\u79f0\u4e3a\u6210\u672c\uff0c\u5982\u679c\u4e00\u4e2a\u56fe\u7684\u9876\u70b9\u5bf9\u662f\u6709\u5e8f\u7684\uff0c\u5219\u79f0\u4e4b\u4e3a",r.a.createElement("strong",null,"\u6709\u5411\u56fe"),"\uff0c\u5728\u5bf9\u6709\u5411\u56fe\u4e2d\u7684\u9876\u70b9\u6392\u5e8f\u540e\uff0c\u4fbf\u53ef\u4ee5\u5728\u9876\u70b9\u4e4b\u95f4\u7ed8\u5236\u4e00\u4e2a\u7bad\u5934\uff0c\u6709\u5411\u56fe\u8868\u660e\u4e86\u9876\u70b9\u7684\u6d41\u5411\uff0c\u6d41\u7a0b\u56fe\u5c31\u662f\u4e00\u4e2a\u6709\u5411\u56fe\u7684\u4f8b\u5b50")),r.a.createElement("li",null,r.a.createElement("p",null,"\u5982\u679c\u56fe\u662f\u65e0\u5e8f\u7684\uff0c\u5c31\u79f0\u4e3a",r.a.createElement("strong",null,"\u65e0\u5e8f\u56fe"),"\u6216",r.a.createElement("strong",null,"\u65e0\u5411\u56fe"))),r.a.createElement("li",null,r.a.createElement("p",null,"\u4ece\u4e00\u4e2a\u8282\u70b9\u8d70\u5230\u53e6\u4e00\u4e2a\u8282\u70b9\u7684\u8fd9\u4e00\u7ec4\u8fb9\u79f0\u4e3a",r.a.createElement("strong",null,"\u8def\u5f84"),"\uff0c\u8def\u5f84\u4e2d\u6240\u6709\u7684\u9876\u70b9\u90fd\u7531\u8fb9\u8fde\u63a5\uff0c\u8def\u5f84\u7684\u957f\u5ea6\u7528\u8def\u5f84\u4e2d\u7684\u7b2c\u4e00\u4e2a\u9876\u70b9\u5230\u6700\u540e\u4e00\u4e2a\u9876\u70b9\u4e4b\u95f4\u8fb9\u7684\u6570\u91cf\u8868\u793a\uff0c\u6307\u5411\u81ea\u8eab\u7684\u9876\u70b9\u7ec4\u6210\u7684\u8def\u5f84\u79f0\u4e3a",r.a.createElement("strong",null,"\u73af"),"\uff0c\u73af\u7684\u957f\u5ea6\u4e3a 0")),r.a.createElement("li",null,r.a.createElement("p",null,"\u5708\u662f\u81f3\u5c11\u6709\u4e00\u6761\u8fb9\u7684\u8def\u5f84\uff0c\u4e14\u8def\u5f84\u7684\u7b2c\u4e00\u4e2a\u9876\u70b9\u548c\u6700\u540e\u4e00\u4e2a\u9876\u70b9\u76f8\u540c\uff0c\u65e0\u8bba\u6709\u5411\u56fe\u8fd8\u662f\u65e0\u5411\u56fe\u53ea\u8981\u662f\u6ca1\u6709\u91cd\u590d\u7684\u9876\u70b9\u7684\u5708\u5c31\u662f\u4e00\u4e2a",r.a.createElement("strong",null,"\u7b80\u5355\u5708"),"\uff0c\u9664\u4e86\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u9876\u70b9\u5916\uff0c\u8def\u5f84\u7684\u5176\u4ed6\u9876\u70b9\u6709\u91cd\u590d\u7684\u5708\u6210\u4e3a",r.a.createElement("strong",null,"\u5e73\u51e1\u5708"))),r.a.createElement("li",null,r.a.createElement("p",null,"\u5982\u679c\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u6709\u8def\u5f84\uff0c\u90a3\u4e48\u8fd9\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u5c31\u662f\u5f3a\u8fde\u901a\u7684\uff0c\u5982\u679c\u6709\u5411\u56fe\u7684\u6240\u6709\u9876\u70b9\u90fd\u662f",r.a.createElement("strong",null,"\u5f3a\u8fde\u901a"),"\u7684\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6709\u5411\u56fe\u4e5f\u662f\u5f3a\u8fde\u901a\u7684\u3002"))),r.a.createElement("h2",{id:"\u4ee3\u7801\u5b9e\u73b0"},r.a.createElement(s["AnchorLink"],{to:"#\u4ee3\u7801\u5b9e\u73b0","aria-hidden":"true",tabIndex:-1},r.a.createElement("span",{className:"icon icon-link"})),"\u4ee3\u7801\u5b9e\u73b0"),r.a.createElement(l["a"],{code:"function Graph(v) {\n this.vertices = v;\n this.edges = 0; //\u8868\u793a\u8fb9\n this.adj = []; //\u94fe\u63a5\u7684\u8fb9\n this.marked = []; //\u8868\u793a\u662f\u5426\u8bbf\u95ee\u8fc7\n for (let i = 0; i < this.vertices; i++) {\n this.adj[i] = [];\n this.marked[i] = false;\n }\n this.addEdge = addEdge;\n this.showGraph = showGraph;\n this.dfs = dfs; //\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\n this.bfs = bfs; //\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\n this.edgeTo = [];\n this.hasPathTo = hasPathTo;\n this.pathTo = pathTo;\n}\n//\u6dfb\u52a0\u70b9\nfunction addEdge(v, w) {\n this.adj[v].push(w);\n this.adj[w].push(v);\n this.edges++;\n}\n//\u663e\u793a\u56fe\nfunction showGraph() {\n for (var i = 0; i < this.vertices; i++) {\n var edges = '';\n for (j = 0; j < this.vertices; j++) {\n if (this.adj[i][j]) {\n edges += this.adj[i][j] + ' ';\n }\n }\n console.log(i + '-> ' + edges);\n }\n}\n\n//\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\nfunction dfs(v) {\n this.marked[v] = true;\n if (this.adj[v] != undefined) {\n console.log(v + '\u5df2\u7ecf\u88ab\u8bbf\u95ee\u4e86');\n }\n for (var w in this.adj[v]) {\n var current = this.adj[v][w];\n if (!this.marked[current]) {\n this.dfs(current);\n }\n }\n}\n//\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\nfunction bfs(s) {\n var queue = [];\n this.marked[s] = true;\n queue.push(s);\n while (queue.length > 0) {\n var v = queue.shift();\n if (v != undefined) {\n console.log('bfs ' + v + '\u5df2\u7ecf\u88ab\u8bbf\u95ee');\n }\n\n for (var w in this.adj[v]) {\n var current = this.adj[v][w];\n if (!this.marked[current]) {\n this.marked[current] = true;\n this.edgeTo[current] = v;\n queue.push(current);\n }\n }\n }\n}\n\nfunction hasPathTo(v) {\n return this.marked[v];\n}\n//\u6700\u77ed\u8def\u5f84\nfunction pathTo(v) {\n var source = 0;\n if (!this.hasPathTo(v)) {\n return undefined;\n }\n var path = [];\n for (var i = v; i != source; i = this.edgeTo[i]) {\n path.push(i);\n }\n path.push(source);\n return path;\n}\n\nvar g = new Graph(5);\ng.addEdge(0, 1);\ng.addEdge(0, 2);\ng.addEdge(1, 3);\ng.addEdge(2, 4);\ng.showGraph();\n\n// g.dfs(0)\ng.bfs(0);\nvar paths = g.pathTo(4);\nvar str = '';\nwhile (paths.length > 0) {\n if (paths.length > 1) {\n str += paths.pop() + '->';\n } else {\n str += paths.pop();\n }\n}\nconsole.log(str);",lang:"js"})))}));e["default"]=n=>{var e=r.a.useContext(s["context"]),t=e.demos;return r.a.useEffect((()=>{var e;null!==n&&void 0!==n&&null!==(e=n.location)&&void 0!==e&&e.hash&&s["AnchorLink"].scrollToAnchor(decodeURIComponent(n.location.hash.slice(1)))}),[]),r.a.createElement(i,{demos:t})}}}]);