{"id":280,"date":"2025-12-24T16:29:54","date_gmt":"2025-12-24T08:29:54","guid":{"rendered":"https:\/\/www.xunfen.cloud\/?p=280"},"modified":"2025-12-24T16:29:54","modified_gmt":"2025-12-24T08:29:54","slug":"%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%842-1-%e6%a0%88%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/blog.xunfen.cloud\/?p=280","title":{"rendered":"\u6570\u636e\u7ed3\u67842.1-\u6808(\u6570\u7ec4)"},"content":{"rendered":"<h1>\u6808(\u6570\u7ec4)<\/h1>\n<h2>1.\u4f55\u4e3a<\/h2>\n<p>\u6808\u53ef\u4ee5\u770b\u6210\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u7ebf\u6027\u8868\uff0c\u4f46\u662f\u8fd9\u79cd\u7ebf\u6027\u8868\u7684\u5220\u9664\u4e0e\u63d2\u5165\u90fd\u53ea\u5728\u4e00\u7aef\u8fdb\u884c\uff0c\u6b64\u5904\uff0c\u6211\u4eec\u79f0\u4e3a<strong>\u6808\u9876<\/strong>\uff0c\u800c\u4e0d\u8fdb\u884c\u64cd\u4f5c\u7684\u4e00\u6bb5\u79f0\u4e3a<strong>\u6808\u5e95<\/strong><br \/>\n\u6b64\u5904\u6211\u4eec\u7ed9\u51fa\u6808\u7684\u793a\u610f\u56fe<\/p>\n<pre><code>\u6808\u9876\uff08top\uff09\u2192  [\u5143\u7d204]  \u2190 \u6700\u540e\u5165\u6808\u7684\u5143\u7d20\n             [\u5143\u7d203]\n             [\u5143\u7d202]\n             [\u5143\u7d201]\n\u6808\u5e95\uff08bottom\uff09[\u5143\u7d200]  \u2190 \u6700\u5148\u5165\u6808\u7684\u5143\u7d20<\/code><\/pre>\n<p>\u6b64\u5904\u6211\u4eec\u53ef\u4ee5\u76f4\u89c2\u77e5\u9053<strong>\u5148\u5165\u6808\u7684\u5143\u7d20\u5728\u6808\u5e95\uff0c\u540e\u5165\u6808\u7684\u5143\u7d20\u5728\u6808\u9876<\/strong>\uff0c\u800c\u5143\u7d20\u5fc5\u987b\u5148\u5165\u6808\u624d\u80fd\u51fa\u6808\uff0c\u540c\u65f6\u5143\u7d20\u5fc5\u987b\u5728\u6808\u9876\u624d\u80fd\u51fa\u6808\uff0c\u5426\u5219\u4f1a\u88ab\u4e0a\u9762\u7684\u5143\u538b\u7740\u51fa\u4e0d\u53bb\uff0c\u6b64\u5904\u6211\u4eec\u53ef\u4ee5\u8054\u60f3\u6210\u4e00\u4e2a\u6709\u9650\u957f\u5ea6\u7684\u3001\u4ec5\u5141\u8bb8\u4e00\u4eba\u8fdb\u51fa\u7684\u6709\u9650\u901a\u9053<br \/>\n\u6b64\u5904\u6211\u4eec\u5c31\u4e0d\u4f7f\u7528\u4f2a\u4ee3\u7801\u793a\u610f\u4e86\uff0c\u76f4\u63a5\u7ed3\u5408C\u8bed\u8a00\u4ee3\u7801\u6765\u8bf4\u660e<\/p>\n<h2>2.\u6808\u7684\u64cd\u4f5c<\/h2>\n<p>\u6808\u7684\u64cd\u4f5c\u6709\uff1a<strong>\u5165\u6808<\/strong>\u3001<strong>\u51fa\u6808(\u9000\u6808)<\/strong>\u3001<strong>\u53d6\u6808\u9876\u5143\u7d20<\/strong>\u3001<strong>\u5224\u6808\u7a7a\/\u6ee1<\/strong><\/p>\n<h3>2.1\u521d\u59cb\u5316<\/h3>\n<pre><code class=\"language-C\">#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\n#define MAX_SIZE 10         \/\/\u5b9a\u4e49\u6808\u7684\u6700\u5927\u5bb9\u91cf\n\n\/\/\u521d\u59cb\u5316\u6808\ntypedef struct {\n    int data[MAX_SIZE];      \/\/ \u5b9a\u4e49\u5b58\u50a8\u6808\u5143\u7d20\u7684\u6570\u7ec4\n    int top;                 \/\/ \u5b9a\u4e49\u6808\u9876\u6307\u9488\n} stack;<\/code><\/pre>\n<h3>2.2\u5165\u6808<\/h3>\n<pre><code class=\"language-C\">if (stack.top == MAX_SIZE - 1) {\n        printf(\"\u6808\u5df2\u6ee1,\u8bf7\u5148\u51fa\u6808n\");\n    } else {\n        stack.data[stack.top + 1] = 1;      \/\/\u5199\u5165\u4e00\u4e2a\u5143\u7d20\uff0c\u82e5\u679c\u60f3\u8981\u6279\u91cf\u5199\u5165\u5219\u5faa\u73af\u5373\u53ef\n        stack.top++;                        \/\/\u6808\u9876\u6307\u9488\u52a01\n        printf(\"\u5165\u6808\u6210\u529fn\");\n    }<\/code><\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong> 1.\u5199\u5165\u6570\u636e\u65f6\u52a1\u5fc5<strong>\u5224\u6808\u6ee1<\/strong>\uff0c\u5373\u5bf9\u5e94\u4ee3\u7801<em>if (stack.top == MAX_SIZE &#8211; 1)&#8230;<\/em>\uff0c\u6808\u6ee1\u5219\u65e0\u6cd5\u5199\u5165\u6570\u636e<\/p>\n<ol start=\"2\">\n<li>\u5143\u7d20\u5165\u6808\u540e\u52a1\u5fc5<strong>\u79fb\u52a8\u6808\u9876\u6307\u9488<\/strong>\u4ee3\u8868\u6808\u7684\u5b9e\u9645\u5bb9\u91cf\u589e\u52a0\uff0c\u5426\u5219\u4f1a\u4e22\u5931\u6570\u636e<br \/>\n3.\u5176\u6b21\uff0c\u6211\u4eec\u64cd\u4f5c\u65f6\u8bf7\u52a1\u5fc5\u4f7f\u7528\u6808\u9876\u6307\u9488\uff0c\u4e0d\u8981\u76f4\u63a5\u5728\u7d22\u5f15\u4e0a\u64cd\u4f5c\uff0c\u5426\u5219\u4f1a\u6709\u4e00\u4e9b\u5947\u5947\u602a\u602a\u7684\u95ee\u9898\uff0c\u540c\u65f6\u4e5f\u4e0d\u7b26\u5408\u6808\u7684\u903b\u8f91<\/li>\n<\/ol>\n<h3>2.3\u51fa\u6808(\u9000\u6808)<\/h3>\n<pre><code class=\"language-C\">if (stack.top == -1) {\n        printf(\"\u6808\u5df2\u7a7a,\u8bf7\u5148\u5165\u6808n\");\n    } else {\n        printf(\"\u51fa\u6808\u5143\u7d20\u4e3a%dn\", stack.data[stack.top]);\n        stack.top--;\n    }<\/code><\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong> 1.\u51fa\u6808\u65f6\u52a1\u5fc5<strong>\u5224\u6808\u7a7a<\/strong>\uff0c\u5373\u5bf9\u5e94\u4ee3\u7801<em>if (stack.top == -1)&#8230;<\/em>\uff0c\u6808\u7a7a\u5219\u65e0\u6cd5\u8fdb\u884c\u51fa\u6808\u64cd\u4f5c<\/p>\n<ol start=\"2\">\n<li>\u51fa\u6808\u65f6\u52a1\u5fc5<strong>\u79fb\u52a8\u6808\u9876\u6307\u9488<\/strong>\u4ee3\u8868\u6808\u7684\u5b9e\u9645\u5bb9\u91cf\u51cf\u5c11\uff0c\u5426\u5219\u4f1a\u4e22\u5931\u6570\u636e<br \/>\n3.\u5176\u6b21\uff0c\u6211\u4eec\u64cd\u4f5c\u65f6\u8bf7\u52a1\u5fc5\u4f7f\u7528\u6808\u9876\u6307\u9488\uff0c\u4e0d\u8981\u76f4\u63a5\u5728\u7d22\u5f15\u4e0a\u64cd\u4f5c\uff0c\u5426\u5219\u4f1a\u6709\u4e00\u4e9b\u5947\u5947\u602a\u602a\u7684\u95ee\u9898\uff0c\u540c\u65f6\u4e5f\u4e0d\u7b26\u5408\u6808\u7684\u903b\u8f91<br \/>\n<em>(\u6211\u662f\u4e13\u4e1a\u7684CV\u7a0b\u5e8f\u5458\u563f\u563f\uff3e\u25bd\uff3e)<\/em><br \/>\n\u540c\u65f6\uff0c\u6211\u5728\u5b66\u4e60\u7684\u65f6\u5019\u6709\u4e00\u4e2a\u7591\u95ee\uff0c\u6211\u51fa\u6808\u4e0d\u7528\u628a\u51fa\u53bb\u7684\u90a3\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u5f52\u96f6\u5417\uff0c\u67e5\u9605\u8d44\u6599\u540e\u5f97\u5230\u4ee5\u4e0b\u56de\u7b54\uff1a<br \/>\n\u4e0d\u9700\u8981\u5c06\u51fa\u6808\u5143\u7d20\u7684\u7d22\u5f15\u4f4d\u7f6e\u5f52\u96f6\uff0c\u51fa\u6808\u64cd\u4f5c\u7684\u6838\u5fc3\u662f\u79fb\u52a8\u6808\u9876\u6307\u9488\uff0c\u5f53\u6808\u9876\u6307\u9488\u51cf1\u540e\uff0c\u8be5\u4f4d\u7f6e\u7684\u5143\u7d20\u5728\u903b\u8f91\u4e0a\u5df2\u4e0d\u5728\u6808\u4e2d\uff0c\u540e\u7eed\u5165\u6808\u4f1a\u76f4\u63a5\u8986\u76d6\u8be5\u4f4d\u7f6e\u7684\u6570\u636e<\/li>\n<\/ol>\n<h3>2.4\u53d6\u6808\u9876\u5143\u7d20\u4ee5\u53ca\u904d\u5386\u6808<\/h3>\n<pre><code class=\"language-C\">if (stack.top == -1) {\n        printf(\"\u6808\u5df2\u7a7a,\u8bf7\u5148\u5165\u6808n\");\n    } else {\n        printf(\"\u6808\u9876\u5143\u7d20\u4e3a%dn\", stack.data[stack.top]);\n        printf(\"\u6808\u4e2d\u5143\u7d20\u4e2a\u6570\u4e3a%dn\", stack.top + 1);\n        printf(\"\u6808\u4e2d\u5143\u7d20\u4e3a:n\");\n        for (int i = 0; i &lt;= stack.top; i++) {\n            printf(\"%dn\", stack.data[i]);\n            printf(\"n\");\n        }\n    }<\/code><\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong> 1.\u53d6\u6808\u9876\u5143\u7d20\u65f6\u52a1\u5fc5<strong>\u5224\u6808\u7a7a<\/strong>\uff0c\u5373\u5bf9\u5e94\u4ee3\u7801<em>if (stack.top == -1)&#8230;<\/em>\uff0c\u6808\u7a7a\u5219\u65e0\u6cd5\u8fdb\u884c\u53d6\u6808\u9876\u5143\u7d20\u64cd\u4f5c<br \/>\n2.\u597d\u50cf\u6ca1\u4e86<\/p>\n<h2>3.\u7ed3<\/h2>\n<p>\u4ee5\u4e0a\u5c31\u662f\u7528\u6570\u7ec4\u5b9e\u73b0\u6808\u7684\u4e00\u4e9b\u793a\u4f8b\u4e86\uff0c\u8fd8\u662f\u6bd4\u8f83\u7b80\u5355\u7684\uff0c\u7528\u94fe\u8868\u6765\u6a21\u62df\u6808\u5c31\u8981\u5934\u75bc\u4e86(\uff20_\uff20;)\uff0c\u6211\u4f1a\u5c3d\u529b\u5b66\u4e60\u7136\u540e\u5199\u51fa\u6765\u7684<br \/>\n\u5b8c\u6574\u4ee3\u7801\u53ef\u4ee5\u5728\u540c\u6587\u4ef6\u5939\u4e0b\u7684.\/stackDemo1.c\u4e2d\u627e\u5230,\u535a\u5ba2\u7684\u8bdd\u4f1a\u628a\u4ee3\u7801\u9644\u5728\u8bc4\u8bba\u533a<br \/>\n\u611f\u8c22\u652f\u6301\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6808(\u6570\u7ec4) 1.\u4f55\u4e3a \u6808\u53ef\u4ee5\u770b\u6210\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u7ebf\u6027\u8868\uff0c\u4f46\u662f\u8fd9\u79cd\u7ebf\u6027\u8868\u7684\u5220\u9664\u4e0e\u63d2\u5165\u90fd\u53ea\u5728\u4e00\u7aef\u8fdb\u884c\uff0c\u6b64\u5904\uff0c\u6211\u4eec\u79f0\u4e3a\u6808 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2,6],"tags":[],"class_list":["post-280","post","type-post","status-publish","format-standard","hentry","category-2","category-6"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=\/wp\/v2\/posts\/280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=280"}],"version-history":[{"count":0,"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=\/wp\/v2\/posts\/280\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.xunfen.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}