-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs__algorithm__datasources__linklist.md.js
More file actions
1 lines (1 loc) · 9.57 KB
/
docs__algorithm__datasources__linklist.md.js
File metadata and controls
1 lines (1 loc) · 9.57 KB
1
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([[7],{"+wmT":function(e,n,t){"use strict";t.r(n);var r=t("q1tI"),i=t.n(r),l=t("dEAq"),o=t("H1Ra"),a=i.a.memo((e=>{e.demos;return i.a.createElement(i.a.Fragment,null,i.a.createElement("div",{className:"markdown"},i.a.createElement("h2",{id:"\u4e3a\u4ec0\u4e48\u8981\u7528\u94fe\u8868"},i.a.createElement(l["AnchorLink"],{to:"#\u4e3a\u4ec0\u4e48\u8981\u7528\u94fe\u8868","aria-hidden":"true",tabIndex:-1},i.a.createElement("span",{className:"icon icon-link"})),"\u4e3a\u4ec0\u4e48\u8981\u7528\u94fe\u8868\uff1f"),i.a.createElement("ul",null,i.a.createElement("li",null,"\u6570\u7ec4\u4e0d\u662f\u8bf4\u7ec4\u7ec7\u6570\u636e\u6700\u4f73\u7ed3\u6784"),i.a.createElement("li",null,"javascript \u7684\u6570\u7ec4\u88ab\u5b9e\u73b0\u6210\u4e86\u5bf9\u8c61\uff0c\u4e0e\u5176\u4ed6\u8bed\u8a00\u6570\u7ec4\u76f8\u6bd4\uff0c\u6548\u7387\u4f4e\u4e86\u5f88\u591a"),i.a.createElement("li",null,"\u5982\u679c\u4f60\u53d1\u73b0\u6570\u7ec4\u65f6\u95f4\u4f7f\u7528\u65f6\u5f88\u6162\uff0c\u5c31\u53ef\u4ee5\u8003\u8651\u7528\u94fe\u8868\u4ee3\u66ff\u4ed6\uff0c\u9664\u4e86\u5bf9\u6570\u636e\u7684\u968f\u673a\u8bbf\u95ee\uff0c\u94fe\u63a5\u51e0\u4e4e\u53ef\u4ee5\u7528\u5b50\u554a\u4efb\u4f55\u53ef\u4ee5\u4f7f\u7528\u4e00\u7ef4\u6570\u7ec4\u7684\u5730\u65b9"),i.a.createElement("li",null,"\u5982\u679c\u662f\u60f3\u7701\u7a7a\u95f4\u7684\u8bdd\u53ef\u4ee5\u4f7f\u7528\u94fe\u8868")),i.a.createElement("h2",{id:"\u94fe\u8868\u7684\u6982\u5ff5"},i.a.createElement(l["AnchorLink"],{to:"#\u94fe\u8868\u7684\u6982\u5ff5","aria-hidden":"true",tabIndex:-1},i.a.createElement("span",{className:"icon icon-link"})),"\u94fe\u8868\u7684\u6982\u5ff5\uff1f"),i.a.createElement("ul",null,i.a.createElement("li",null,i.a.createElement("p",null,"\u94fe\u8868\u662f\u7531\u4e00\u7cfb\u5217\u8282\u70b9\u7ec4\u6210\u7684\u96c6\u5408,\u6bcf\u4e2a\u8282\u70b9\u90fd\u4f7f\u7528\u4e00\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\u6307\u5411\u5b83\u7684\u540e\u7ee7\uff0c\u6307\u5411\u53e6\u4e00\u4e2a\u8282\u70b9\u7684\u5f15\u7528\u53eb\u94fe"),i.a.createElement("img",{src:t("8yXg")})),i.a.createElement("li",null,i.a.createElement("p",null,"\u94fe\u8868\u5143\u7d20\u9760\u76f8\u4e92\u4e4b\u95f4\u7684\u5173\u7cfb\u8fdb\u884c\u5f15\u7528 A->B->C,B \u5e76\u4e0d\u662f\u94fe\u8868\u7684\u7b2c\u4e8c\u4e2a\u5143\u7d20\u800c\u662f B \u8ddf\u5728 A \u540e\u9762\uff0c\u904d\u5386\u94fe\u8868\u5c31\u662f\u8ddf\u7740\u94fe\u63a5\uff0c\u4ece\u94fe\u63a5\u7684\u9996\u5143\u7d20\u4e00\u76f4\u5230\u5c3e\u5143\u7d20\uff0c\u4f46\u662f\u4e0d\u5305\u542b",i.a.createElement("strong",null,"\u5934\u8282\u70b9"),"\uff0c\u5934\u5143\u7d20\u5e38\u5e38\u88ab\u79f0\u4e3a\u94fe\u8868\u7684\u63a5\u5165\u70b9\uff08\u94fe\u8868\u7684\u5c3e\u5143\u7d20\u6307\u5411\u4e00\u4e2a null \u8282\u70b9\uff09")),i.a.createElement("li",null,i.a.createElement("p",null,"\u5411\u5355\u5411\u94fe\u8868\u63d2\u5165\u4e00\u4e2a\u8282\u70b9\uff0c\u9700\u8981\u4fee\u6539\u5b83\u524d\u9762\u7684\u8282\u70b9(\u524d\u9a71)\u4f7f\u5176\u6307\u5411\u65b0\u52a0\u5165\u7684\u8282\u70b9\uff0c\u800c\u65b0\u52a0\u5165\u7684\u8282\u70b9\u5219\u6307\u5411\u539f\u6765\u524d\u9a71\u6307\u5411\u7684\u8282\u70b9")),i.a.createElement("li",null,i.a.createElement("p",null,"\u4ece\u5355\u5411\u94fe\u8868\u5220\u9664\u4e00\u4e2a\u5143\u7d20\uff0c\u9700\u8981\u5c06\u5f85\u5220\u9664\u7684\u5143\u7d20\u7684\u524d\u9a71\u8282\u70b9\u6307\u5411\u5f85\u5220\u9664\u5143\u7d20\u7684\u540e\u7ee7\u8282\u70b9\uff0c\u540c\u65f6\u5220\u9664\u5143\u7d20\u6307\u5411 null"),i.a.createElement("img",{src:t("s4lX")})),i.a.createElement("li",null,i.a.createElement("p",null,"\u53cc\u5411\u94fe\u8868"),i.a.createElement("img",{src:t("XiKP")}))),i.a.createElement("h2",{id:"\u94fe\u8868\u7684\u7b80\u5355\u4ee3\u7801\u7406\u89e3"},i.a.createElement(l["AnchorLink"],{to:"#\u94fe\u8868\u7684\u7b80\u5355\u4ee3\u7801\u7406\u89e3","aria-hidden":"true",tabIndex:-1},i.a.createElement("span",{className:"icon icon-link"})),"\u94fe\u8868\u7684\u7b80\u5355\u4ee3\u7801\u7406\u89e3"),i.a.createElement(o["a"],{code:"function ListNode(val) {\n this.val = val;\n this.next = null;\n}\n\nconst node = new ListNode(1);\nnode.next = new ListNode(2);\nconst node3 = new ListNode(3);\nnode3.next = node.next;\nnode.next = node3;\nconsole.log(node);",lang:"js"}),i.a.createElement("h2",{id:"\u4ee3\u7801\u5b9e\u73b0"},i.a.createElement(l["AnchorLink"],{to:"#\u4ee3\u7801\u5b9e\u73b0","aria-hidden":"true",tabIndex:-1},i.a.createElement("span",{className:"icon icon-link"})),"\u4ee3\u7801\u5b9e\u73b0"),i.a.createElement("ol",null,i.a.createElement("li",null,"\u5355\u5411\u94fe\u8868")),i.a.createElement(o["a"],{code:"function Node(element) {\n this.element = element;\n this.next = null; //\u94fe\u8868\u540e\u7ee7\n}\nfunction LList() {\n this.head = new Node('head'); //\u5934\u7ed3\u70b9\n this.find = find;\n this.insert = insert;\n this.display = display;\n this.findPrevious = findPrevious;\n this.remove = remove;\n}\n\n//\u627e\u5230\u8282\u70b9\nfunction find(item) {\n var currentNode = this.head;\n while (currentNode.element !== item) {\n currentNode = currentNode.next;\n }\n return currentNode;\n}\n\n//\u63d2\u5165\u8282\u70b9\nfunction insert(newElement, item) {\n var newNode = new Node(newElement);\n var currNode = this.find(item);\n newNode.next = currNode.next;\n currNode.next = newNode;\n}\n\n//\u904d\u5386\u8282\u70b9\nfunction display() {\n var currNode = this.head;\n while (currNode.next !== null) {\n console.log(currNode.next.element);\n currNode = currNode.next;\n }\n}\n\n//\u627e\u5230\u524d\u9a71\nfunction findPrevious(item) {\n var currNode = this.head;\n while (currNode.next !== null && currNode.next.element !== item) {\n currNode = currNode.next;\n }\n return currNode;\n}\nfunction remove(item) {\n var preNode = this.findPrevious(item);\n var currNode = this.find(item);\n if (preNode.next != null) {\n preNode.next = currNode.next;\n currNode.next = null;\n }\n}\n\nvar cities = new LList();\ncities.insert('first', 'head');\ncities.insert('second', 'first');\ncities.insert('thrid', 'second');\ncities.display();\nconsole.log('=========');\ncities.remove('second');\ncities.display();",lang:"js"}),i.a.createElement("ol",{start:2},i.a.createElement("li",null,"\u53cc\u5411\u94fe\u8868")),i.a.createElement(o["a"],{code:"/**\n * \u53cc\u5411\u94fe\u8868\n */\n\nfunction Node(element) {\n this.element = element;\n this.next = null;\n this.previous = null;\n}\n\nfunction LList() {\n this.head = new Node('head');\n this.find = find;\n this.insert = insert;\n this.display = display;\n this.remove = remove;\n this.findLast = findLast;\n this.dispReverse = dispReverse;\n}\n//\u67e5\u627e\nfunction find(item) {\n var currNode = this.head;\n console.log(currNode);\n while (currNode.element != item) {\n currNode = currNode.next;\n }\n return currNode;\n}\n\n//\u63d2\u5165\nfunction insert(newElement, item) {\n var newNode = new Node(newElement);\n var current = this.find(item);\n newNode.next = current.next;\n newNode.previous = current;\n current.next = newNode;\n if (!(newNode.next == null)) {\n newNode.next.previous = newNode;\n }\n}\nfunction display() {\n var currNode = this.head;\n while (currNode.next != null) {\n console.log(currNode.next.element);\n currNode = currNode.next;\n }\n}\n\nfunction remove(item) {\n var currNode = this.find(item);\n if (!(currNode.next === null)) {\n currNode.previous.next = currNode.next;\n currNode.next.previous = currNode.previous;\n currNode.previous = null;\n currNode.next = null;\n } else {\n currNode.previous.next = null;\n currNode.previous = null;\n }\n}\n//\u67e5\u627e\u6700\u540e\u4e00\u4e2a\u8282\u70b9\nfunction findLast() {\n var currNode = this.head;\n while (currNode.next !== null) {\n currNode = currNode.next;\n }\n return currNode;\n}\n//\u53cd\u5e8f\nfunction dispReverse() {\n var currNode = this.findLast();\n while (currNode.previous !== null) {\n console.log(currNode.element);\n currNode = currNode.previous;\n }\n}\nvar cities = new LList();\ncities.insert('first', 'head');\ncities.insert('second', 'first');\ncities.insert('thrid', 'second');\ncities.display();\nconsole.log('=====');\ncities.remove('second');\ncities.display();\nconsole.log('=====');\n\ncities.dispReverse();",lang:"js"}),i.a.createElement("h2",{id:"\u94fe\u8868\u548c\u6570\u7ec4\u7684\u4f18\u52bf"},i.a.createElement(l["AnchorLink"],{to:"#\u94fe\u8868\u548c\u6570\u7ec4\u7684\u4f18\u52bf","aria-hidden":"true",tabIndex:-1},i.a.createElement("span",{className:"icon icon-link"})),"\u94fe\u8868\u548c\u6570\u7ec4\u7684\u4f18\u52bf"),i.a.createElement("p",null,"\u5bf9\u4e8e\u6570\u7ec4 ",i.a.createElement("code",null,"for"),"\u5faa\u73af\u7684\u901f\u5ea6\u5feb\u4e8e",i.a.createElement("code",null,"forEach"),"\u548c",i.a.createElement("code",null,"map"),"\u94fe\u8868\u7684",i.a.createElement("strong",null,"\u63d2\u5165/\u5220\u9664"),"\u6548\u7387\u8f83\u9ad8\uff0c\u800c",i.a.createElement("strong",null,"\u8bbf\u95ee"),"\u6548\u7387\u8f83\u4f4e\uff1b\u6570\u7ec4\u7684",i.a.createElement("strong",null,"\u8bbf\u95ee"),"\u6548\u7387\u8f83\u9ad8\uff0c\u800c",i.a.createElement("strong",null,"\u63d2\u5165"),"\u6548\u7387\u8f83\u4f4e")))}));n["default"]=e=>{var n=i.a.useContext(l["context"]),t=n.demos;return i.a.useEffect((()=>{var n;null!==e&&void 0!==e&&null!==(n=e.location)&&void 0!==n&&n.hash&&l["AnchorLink"].scrollToAnchor(decodeURIComponent(e.location.hash.slice(1)))}),[]),i.a.createElement(a,{demos:t})}},"8yXg":function(e,n,t){e.exports=t.p+"static/link.341f927c.png"},XiKP:function(e,n,t){e.exports=t.p+"static/\u53cc\u5411\u94fe\u8868.0f2395e9.png"},s4lX:function(e,n,t){e.exports=t.p+"static/\u5355\u94fe\u8868.f62fa292.png"}}]);