-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs__algorithm__datasources__queue.md.js
More file actions
1 lines (1 loc) · 7.95 KB
/
docs__algorithm__datasources__queue.md.js
File metadata and controls
1 lines (1 loc) · 7.95 KB
1
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([[8],{EBRg:function(e,n,t){"use strict";t.r(n);var a=t("q1tI"),l=t.n(a),r=t("dEAq"),u=t("H1Ra"),i=l.a.memo((e=>{e.demos;return l.a.createElement(l.a.Fragment,null,l.a.createElement("div",{className:"markdown"},l.a.createElement("h2",{id:"\u961f\u5217\u7684\u6982\u5ff5"},l.a.createElement(r["AnchorLink"],{to:"#\u961f\u5217\u7684\u6982\u5ff5","aria-hidden":"true",tabIndex:-1},l.a.createElement("span",{className:"icon icon-link"})),"\u961f\u5217\u7684\u6982\u5ff5"),l.a.createElement("p",null,"\u961f\u5217\u5c31\u50cf\u94f6\u884c\u6392\u961f\u529e\u7406\u4e1a\u52a1\u7684\u4eba\u7fa4\uff0c\u6392\u5728\u6700\u524d\u9762\u7684\u7b2c\u4e00\u4e2a\u529e\u7406\u4e1a\u52a1\uff0c\u65b0\u6765\u7684\u6392\u5728\u540e\u9762\uff0c\u77e5\u9053\u8f6e\u5230\u4ed6\u4eec\u4e3a\u6b62\uff0c"),l.a.createElement("p",null,l.a.createElement("strong",null,"\u7528\u9014")),l.a.createElement("ul",null,l.a.createElement("li",null,"\u6d88\u606f\u961f\u5217\u3001\u89c6\u9891\u5f39\u5e55"),l.a.createElement("li",null,"\u7ef4\u62a4\u6253\u5370\u673a\u4efb\u52a1")),l.a.createElement("p",null,l.a.createElement("strong",null,"\u603b\u7ed3")),l.a.createElement("ul",null,l.a.createElement("li",null,"\u961f\u5217\u5c31\u662f",l.a.createElement("strong",null,"\u5148\u8fdb\u5148\u51fa"),"\u7684\u6570\u636e\u7ed3\u6784"),l.a.createElement("li",null,"\u961f\u5217\u53ea\u80fd\u5728\u961f\u5c3e\u63d2\u5165\u5143\u7d20\uff0c\u5728\u961f\u9996\u5220\u9664\u5143\u7d20"),l.a.createElement("li",null,"\u63d2\u5165\u65b0\u5143\u7d20\u53eb\u5165\u961f\uff0c\u5220\u9664\u64cd\u4f5c\u53eb\u51fa\u961f"),l.a.createElement("li",null,"\u6709\u4e00\u4e9b\u7279\u6b8a\u7684\u60c5\u51b5\uff0c\u5728\u5220\u9664\u7684\u65f6\u5019\u4e0d\u5fc5\u8981\u9075\u5b88\u5148\u8fdb\u5148\u51fa\u7684\u7ea6\u5b9a\uff0c\u8fd9\u79cd\u53eb\u505a\u4f18\u5148\u961f\u5217\u7684\u6570\u636e\u7ed3\u6784")),l.a.createElement("h2",{id:"\u961f\u5217\u7684\u7b80\u5355\u4ee3\u7801\u5b9e\u73b0"},l.a.createElement(r["AnchorLink"],{to:"#\u961f\u5217\u7684\u7b80\u5355\u4ee3\u7801\u5b9e\u73b0","aria-hidden":"true",tabIndex:-1},l.a.createElement("span",{className:"icon icon-link"})),"\u961f\u5217\u7684\u7b80\u5355\u4ee3\u7801\u5b9e\u73b0"),l.a.createElement(u["a"],{code:"var queue = [];\nqueue.push('\u4e1c\u5317\u5927\u677f');\nqueue.push('\u53ef\u7231\u591a');\nqueue.push('\u5de7\u4e50\u5179');\nqueue.push('\u5149\u660e\u5976\u7816');\n\nlet i = 0;\nwhile (queue.length) {\n console.log('\u73b0\u5728\u53d6\u51fa\u7684\u662f', queue[0]);\n queue.shift();\n console.log(queue);\n}",lang:"js"}),l.a.createElement("p",null,"\u51fa\u73b0\u7684\u7ed3\u679c\u5982\u4e0b\u56fe\uff1a"),l.a.createElement("img",{src:t("dNTH")}),l.a.createElement("h2",{id:"\u961f\u5217\u7684\u5b9e\u73b0javascript"},l.a.createElement(r["AnchorLink"],{to:"#\u961f\u5217\u7684\u5b9e\u73b0javascript","aria-hidden":"true",tabIndex:-1},l.a.createElement("span",{className:"icon icon-link"})),"\u961f\u5217\u7684\u5b9e\u73b0(javascript)"),l.a.createElement(u["a"],{code:"function Queue() {\n this.dataStore = []; //\u6570\u636e\u6e90\n this.enqueue = enqueue; //\u961f\u5c3e\u589e\u52a0\u4e00\u4e2a\n this.dequeue = dequeue; //\u5220\u9664\u961f\u9996\n this.front = front; //\u8bfb\u53d6\u961f\u9996\n this.back = back; //\u8bfb\u53d6\u961f\u5c3e\n this.toString = toString; //\u663e\u793a\u961f\u5217\u6240\u6709\u5143\u7d20\n this.isEmpty = isEmpty; //\u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\n}\n//\u5165\u961f\nfunction enqueue(value) {\n this.dataStore.push(value);\n}\n//\u51fa\u961f\nfunction dequeue() {\n return this.dataStore.shift();\n}\n//\u961f\u9996\nfunction front() {\n return this.dataStore[0];\n}\n//\u961f\u5c3e\nfunction back() {\n return this.dataStore[this.dataStore.length - 1];\n}\n// \u662f\u5426\u4e3a\u7a7a\u961f\u5217\nfunction isEmpty() {\n if (this.dataStore.length === 0) {\n return true;\n } else {\n return false;\n }\n}\n// \u67e5\u770b\u6574\u4e2a\u961f\u5217\nfunction toString() {\n let str = '';\n for (let i = 0; i < this.dataStore.length; i++) {\n str += this.dataStore[i] + '\\n';\n }\n return str;\n}\n\n// let queue=new Queue();\n// queue.enqueue('\u5c0f\u738b')\n// queue.enqueue('\u5c0f\u540d')\n// queue.enqueue('\u5c0f\u53eb')\n// console.log(queue.toString())\n// queue.dequeue()\n// console.log(queue.toString())\n// queue.dequeue()\n// console.log(queue.toString())",lang:"js"}),l.a.createElement("h2",{id:"\u5faa\u73af\u961f\u5217"},l.a.createElement(r["AnchorLink"],{to:"#\u5faa\u73af\u961f\u5217","aria-hidden":"true",tabIndex:-1},l.a.createElement("span",{className:"icon icon-link"})),"\u5faa\u73af\u961f\u5217"),l.a.createElement("p",null,"\u5faa\u73af\u961f\u5217\u662f\u4e00\u79cd\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u5176\u64cd\u4f5c\u8868\u73b0\u57fa\u4e8e FIFO\uff08\u5148\u8fdb\u5148\u51fa\uff09\u539f\u5219\u5e76\u4e14\u961f\u5c3e\u88ab\u8fde\u63a5\u5728\u961f\u9996\u4e4b\u540e\u4ee5\u5f62\u6210\u4e00\u4e2a\u5faa\u73af\u3002\u5b83\u4e5f\u88ab\u79f0\u4e3a\u201c\u73af\u5f62\u7f13\u51b2\u5668\u201d"),l.a.createElement("p",null,"\u5faa\u73af\u961f\u5217\u7684\u4e00\u4e2a\u597d\u5904\u662f\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u8fd9\u4e2a\u961f\u5217\u4e4b\u524d\u7528\u8fc7\u7684\u7a7a\u95f4\u3002\u5728\u4e00\u4e2a\u666e\u901a\u961f\u5217\u91cc\uff0c\u4e00\u65e6\u4e00\u4e2a\u961f\u5217\u6ee1\u4e86\uff0c\u6211\u4eec\u5c31\u4e0d\u80fd\u63d2\u5165\u4e0b\u4e00\u4e2a\u5143\u7d20\uff0c\u5373\u4f7f\u5728\u961f\u5217\u524d\u9762\u4ecd\u6709\u7a7a\u95f4\u3002\u4f46\u662f\u4f7f\u7528\u5faa\u73af\u961f\u5217\uff0c\u6211\u4eec\u80fd\u4f7f\u7528\u8fd9\u4e9b\u7a7a\u95f4\u53bb\u5b58\u50a8\u65b0\u7684\u503c"),l.a.createElement(u["a"],{code:"class MyCircularQueue {\n constructor(k) {\n this.list = Array(k); // \u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3ak\u7684\u7a7a\u6570\u7ec4\n this.front = 0; // \u4fdd\u5b58\u5934\u90e8\u6307\u9488\u4f4d\u7f6e\n this.real = 0; // \u4fdd\u5b58\u5c3e\u90e8\u6307\u9488\u4f4d\u7f6e\n this.max = k; // \u4fdd\u5b58\u8be5\u6570\u7ec4\u6700\u5927\u957f\u5ea6\uff0c\u4e5f\u5c31\u662fk\n }\n Front() {\n //\u53d6\u961f\u9996\u7684\u5143\u7d20\n if (this.isEmpty()) {\n return -1;\n }\n return this.list[this.front];\n }\n Rear() {\n //\u53bb\u961f\u5c3e\u7684\u5143\u7d20 \u5982\u679c\u662f\u6ee1\u961f\u7684\u60c5\u51b5 \u5c31\u53d6\u6700\u5927\u503c\u7684\u6700\u540e\u4e00\u4f4d\uff0c\u5426\u5219\u5c31\u53d6\u5f53\u524d\u6240\u6709\u5143\u7d20\u6700\u5927\u7684\u4e00\u4f4d\n if (this.isEmpty()) {\n return -1;\n }\n let val = this.real - 1 >= 0 ? this.real - 1 : this.max - 1;\n return this.list[val];\n }\n enQueue(value) {\n //\u5165\u6808\n if (!this.isFull()) {\n this.list[this.real] = value;\n this.real = (this.real + 1) % this.max;\n return true;\n } else {\n return false;\n }\n }\n deQueue() {\n //\u51fa\u6808\n if (!this.isEmpty()) {\n this.list[this.front] = '';\n this.front = (this.front + 1) % this.max;\n return true;\n } else {\n return false;\n }\n }\n isEmpty() {\n //\u662f\u5426\u4e3a\u7a7a \u5224\u65ad\u6761\u4ef6\u662f\u9996\u5c3e\u6307\u9488\u76f8\u7b49\uff0c\u5e76\u4e14\u5934\u90e8\u6307\u9488\u6240\u6307\u7684\u5143\u7d20\u4e3a\u7a7a\n if (this.real === this.front && !this.list[this.front]) {\n return true;\n } else {\n return false;\n }\n }\n isFull() {\n //\u5224\u65ad\u662f\u5426\u662f\u6ee1\u6808 \u5224\u65ad\u6761\u4ef6\u662f\u9996\u5c3e\u6307\u9488\u76f8\u7b49\uff0c\u5e76\u4e14\u5934\u90e8\u6307\u9488\u6240\u6307\u7684\u5143\u7d20\u4e0d\u4e3a\u7a7a\n if (this.real === this.front && !!this.list[this.front]) {\n return true;\n } else {\n return false;\n }\n }\n}",lang:"js"})))}));n["default"]=e=>{var n=l.a.useContext(r["context"]),t=n.demos;return l.a.useEffect((()=>{var n;null!==e&&void 0!==e&&null!==(n=e.location)&&void 0!==n&&n.hash&&r["AnchorLink"].scrollToAnchor(decodeURIComponent(e.location.hash.slice(1)))}),[]),l.a.createElement(i,{demos:t})}},dNTH:function(e,n,t){e.exports=t.p+"static/quene.f911cf77.png"}}]);