{"id":35454,"date":"2024-11-26T16:13:47","date_gmt":"2024-11-26T08:13:47","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35454\/"},"modified":"2024-11-26T16:13:47","modified_gmt":"2024-11-26T08:13:47","slug":"java%e4%ba%8c%e7%bb%b4%e6%95%b0%e7%bb%84%e9%98%9f%e5%88%97%e6%80%8e%e4%b9%88%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35454\/","title":{"rendered":"java\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\u600e\u4e48\u7528"},"content":{"rendered":"<blockquote><p>\n  \u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\u662f\u4e00\u79cd\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u5b58\u50a8\u7684\u961f\u5217\u7ed3\u6784\uff0c\u5141\u8bb8\u591a\u884c\u6570\u636e\u7684\u5165\u961f\u548c\u51fa\u961f\u64cd\u4f5c\u3002\u5176\u4f7f\u7528\u65b9\u6cd5\u5305\u62ec\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\u3001\u521d\u59cb\u5316\u961f\u5217\u3001\u5165\u961f\u3001\u51fa\u961f\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e00\u4e2a\u793a\u4f8b\u7c7b\u6765\u6f14\u793a\u5982\u4f55\u5b9e\u73b0\u8be5\u961f\u5217\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/04\/2024110403242755056.jpg\" class=\"aligncenter\" title=\"java\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\u600e\u4e48\u7528\u63d2\u56fe\" alt=\"java\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\u600e\u4e48\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e8c\u7ef4\u6570\u7ec4\u961f\u5217<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\uff1f<\/strong><\/p>\n<p>\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u7c7b\u4f3c\u4e8e\u666e\u901a\u961f\u5217\uff0c\u4f46\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u8fdb\u884c\u5b58\u50a8\u3002\u5b83\u5141\u8bb8\u591a\u884c\u6570\u636e\u5143\u7d20\u7684\u5165\u961f\u548c\u51fa\u961f\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\uff1f<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u8981\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\uff0c\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li> <strong>\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\uff1a<\/strong>\u521b\u5efa\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u4f5c\u4e3a\u961f\u5217\u7684\u5e95\u5c42\u5b58\u50a8\u7ed3\u6784\u3002<\/li>\n<li> <strong>\u521d\u59cb\u5316\u961f\u5217\uff1a<\/strong>\u8bbe\u7f6e\u961f\u5217\u7684 front \u548c rear \u6307\u9488\uff0c\u5b83\u4eec\u6307\u5411\u961f\u5217\u7684\u961f\u9996\u548c\u961f\u5c3e\u3002<\/li>\n<li> <strong>\u5165\u961f\uff1a<\/strong>\u5c06\u6570\u636e\u5143\u7d20\u6dfb\u52a0\u5230\u961f\u5217\u7684\u961f\u5c3e\uff0c\u5e76\u66f4\u65b0 rear \u6307\u9488\u3002<\/li>\n<li> <strong>\u51fa\u961f\uff1a<\/strong>\u4ece\u961f\u5217\u7684\u961f\u9996\u79fb\u9664\u6570\u636e\u5143\u7d20\uff0c\u5e76\u66f4\u65b0 front \u6307\u9488\u3002<\/li>\n<\/ol>\n<p><strong>\u4f7f\u7528\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>public class ArrayQueue2D {\n    private int[][] queue;\n    private int front, rear;\n\n    public ArrayQueue2D(int rows, int columns) {\n        queue = new int[rows][columns];\n        front = -1;\n        rear = -1;\n    }\n\n    public void enqueue(int data) {\n        if (isFull()) {\n            throw new ArrayIndexOutOfBoundsException(\"Queue is full\");\n        }\n        if (front == -1) {\n            front = rear = 0;\n        } else {\n            rear++;\n        }\n        queue[front][rear] = data;\n    }\n\n    public int dequeue() {\n        if (isEmpty()) {\n            throw new ArrayIndexOutOfBoundsException(\"Queue is empty\");\n        }\n        int data = queue[front][rear];\n        if (front == rear) {\n            front = rear = -1;\n        } else {\n            rear--;\n        }\n        return data;\n    }\n\n    public boolean isEmpty() {\n        return front == -1;\n    }\n\n    public boolean isFull() {\n        return rear == queue[0].length - 1;\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\u600e\u4e48\u7528\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\u662f\u4e00\u79cd\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u5b58\u50a8\u7684\u961f\u5217\u7ed3\u6784\uff0c\u5141\u8bb8\u591a\u884c\u6570\u636e\u7684\u5165\u961f\u548c\u51fa\u961f\u64cd\u4f5c\u3002\u5176\u4f7f\u7528\u65b9\u6cd5\u5305\u62ec\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\u3001\u521d\u59cb\u5316\u961f\u5217\u3001\u5165\u961f\u3001\u51fa\u961f\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e00\u4e2a\u793a\u4f8b\u7c7b\u6765\u6f14\u793a\u5982\u4f55\u5b9e\u73b0\u8be5\u961f\u5217\u3002 Java \u4e8c\u7ef4\u6570\u7ec4\u961f\u5217 \u4ec0\u4e48\u662f\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\uff1f \u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u7c7b\u4f3c\u4e8e\u666e\u901a\u961f\u5217\uff0c\u4f46\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u8fdb\u884c\u5b58\u50a8\u3002\u5b83\u5141\u8bb8\u591a\u884c\u6570\u636e\u5143\u7d20\u7684\u5165\u961f\u548c\u51fa\u961f\u64cd\u4f5c\u3002 \u5982\u4f55\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\uff1f \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u8981\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u961f\u5217\uff0c\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\uff1a\u521b\u5efa\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u4f5c\u4e3a\u961f\u5217\u7684\u5e95\u5c42\u5b58\u50a8\u7ed3\u6784\u3002 \u521d\u59cb\u5316\u961f\u5217\uff1a\u8bbe\u7f6e\u961f\u5217\u7684 front \u548c rear \u6307\u9488\uff0c\u5b83\u4eec\u6307\u5411\u961f\u5217\u7684\u961f\u9996\u548c\u961f\u5c3e\u3002 \u5165\u961f\uff1a\u5c06\u6570\u636e\u5143\u7d20\u6dfb\u52a0\u5230\u961f\u5217\u7684\u961f\u5c3e\uff0c\u5e76\u66f4\u65b0 rear \u6307\u9488\u3002 \u51fa\u961f\uff1a\u4ece\u961f\u5217\u7684\u961f\u9996\u79fb\u9664\u6570\u636e\u5143\u7d20\uff0c\u5e76\u66f4\u65b0 front \u6307\u9488\u3002 \u4f7f\u7528\u793a\u4f8b\uff1a public class ArrayQueue2D { private int[][] queue; private int front, rear; public ArrayQueue2D(int rows, int columns) { queue = new int[rows][columns]; front = -1; rear = -1; } public void enqueue(int data) { if [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-35454","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35454","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=35454"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35454\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}