{"id":186,"date":"2019-11-05T09:02:00","date_gmt":"2019-11-05T09:02:00","guid":{"rendered":"https:\/\/imwarming.com\/?p=186"},"modified":"2019-11-05T09:02:00","modified_gmt":"2019-11-05T09:02:00","slug":"%e6%a0%88%e5%92%8c%e5%88%97%e9%98%9f","status":"publish","type":"post","link":"https:\/\/imwarming.com\/?p=186","title":{"rendered":"\u6808\u548c\u5217\u961f"},"content":{"rendered":"<div class=\"cnblogs_code\">\n<pre>#include &lt;iostream&gt;<span style=\"color: #000000;\">\n#include <\/span>&lt;cstdio&gt;<span style=\"color: #000000;\">\n#include<\/span>&lt;bits\/stdc++.h&gt;\n<span style=\"color: #0000ff;\">using<\/span> <span style=\"color: #0000ff;\">namespace<\/span><span style=\"color: #000000;\"> std;\n<\/span><span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u6808<\/span>\ntypedef <span style=\"color: #0000ff;\">struct<\/span><span style=\"color: #000000;\">{\n    <\/span><span style=\"color: #0000ff;\">int<\/span> *<span style=\"color: #0000ff;\">base<\/span><span style=\"color: #000000;\">;\n    <\/span><span style=\"color: #0000ff;\">int<\/span> *<span style=\"color: #000000;\">top;\n    <\/span><span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\"> stacksize;\n}sqstack;\n<\/span><span style=\"color: #0000ff;\">void<\/span> intistack(sqstack &amp;s){<span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u5efa\u6808<\/span>\n    s.<span style=\"color: #0000ff;\">base<\/span>=(<span style=\"color: #0000ff;\">int<\/span> *)<span style=\"color: #0000ff;\">malloc<\/span>(<span style=\"color: #800080;\">100<\/span>*<span style=\"color: #0000ff;\">sizeof<\/span>(<span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\">));\n    <\/span><span style=\"color: #0000ff;\">if<\/span>(!s.<span style=\"color: #0000ff;\">base<\/span>) cout&lt;&lt;<span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">error<\/span><span style=\"color: #800000;\">\"<\/span>&lt;&lt;<span style=\"color: #000000;\">endl;\n    s.top<\/span>=s.<span style=\"color: #0000ff;\">base<\/span><span style=\"color: #000000;\">;\n    s.stacksize<\/span>=<span style=\"color: #800080;\">100<\/span><span style=\"color: #000000;\">;\n}\n<\/span><span style=\"color: #0000ff;\">void<\/span> pushstack(sqstack &amp;s,<span style=\"color: #0000ff;\">int<\/span> m){<span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u5165\u6808<\/span>\n    <span style=\"color: #0000ff;\">if<\/span>(s.top-s.<span style=\"color: #0000ff;\">base<\/span>&gt;=<span style=\"color: #000000;\">s.stacksize){\n        s.<\/span><span style=\"color: #0000ff;\">base<\/span>=(<span style=\"color: #0000ff;\">int<\/span> *)<span style=\"color: #0000ff;\">realloc<\/span>(s.<span style=\"color: #0000ff;\">base<\/span>,(s.stacksize+<span style=\"color: #800080;\">10<\/span>)*<span style=\"color: #0000ff;\">sizeof<\/span>(<span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\">));\n        <\/span><span style=\"color: #0000ff;\">if<\/span>(s.<span style=\"color: #0000ff;\">base<\/span>) cout&lt;&lt;<span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">error<\/span><span style=\"color: #800000;\">\"<\/span>&lt;&lt;<span style=\"color: #000000;\">endl;\n        s.top<\/span>=s.<span style=\"color: #0000ff;\">base<\/span>+<span style=\"color: #000000;\">s.stacksize;\n    }\n    <\/span>*s.top++=<span style=\"color: #000000;\">m;\n}\n<\/span><span style=\"color: #0000ff;\">int<\/span> popstack(sqstack &amp;s,<span style=\"color: #0000ff;\">int<\/span> &amp;m){<span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u51fa\u6808<\/span>\n    <span style=\"color: #0000ff;\">if<\/span>(s.top==s.<span style=\"color: #0000ff;\">base<\/span>) cout&lt;&lt;<span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">error<\/span><span style=\"color: #800000;\">\"<\/span>&lt;&lt;<span style=\"color: #000000;\">endl;\n    m<\/span>=*--<span style=\"color: #000000;\">s.top;\n    <\/span><span style=\"color: #0000ff;\">return<\/span><span style=\"color: #000000;\"> m;\n}\n\n<\/span><span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u94fe\u5217\u961f<\/span>\ntypedef <span style=\"color: #0000ff;\">struct<\/span><span style=\"color: #000000;\"> qnode{\n    <\/span><span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\"> data;\n    qnode <\/span>*<span style=\"color: #000000;\">next;\n}qnode,<\/span>*<span style=\"color: #000000;\">queueptr;\ntypedef <\/span><span style=\"color: #0000ff;\">struct<\/span><span style=\"color: #000000;\">{\n    queueptr first;\n    queueptr last;\n}linkqueue;\n<\/span><span style=\"color: #0000ff;\">int<\/span> initqnode(linkqueue &amp;s){<span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u5efa\u7a7a\u961f<\/span>\n    s.first=s.last=(queueptr)<span style=\"color: #0000ff;\">malloc<\/span>(<span style=\"color: #0000ff;\">sizeof<\/span><span style=\"color: #000000;\">(qnode));\n    <\/span><span style=\"color: #0000ff;\">if<\/span>(!s.first)exit(-<span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">);\n    s.first<\/span>-&gt;next=<span style=\"color: #000000;\">null;\n    <\/span><span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">;\n}\n<\/span><span style=\"color: #0000ff;\">int<\/span> enqueue(linkqueue &amp;s,<span style=\"color: #0000ff;\">int<\/span> e){<span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u5165<\/span>\n    queueptr p=(queueptr)<span style=\"color: #0000ff;\">malloc<\/span>(<span style=\"color: #0000ff;\">sizeof<\/span><span style=\"color: #000000;\">(qnode));\n    <\/span><span style=\"color: #0000ff;\">if<\/span>(!p)exit(-<span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">);\n    p<\/span>-&gt;data=<span style=\"color: #000000;\">e;\n    p<\/span>-&gt;next=<span style=\"color: #000000;\">null;\n    s.last<\/span>-&gt;next=<span style=\"color: #000000;\">p;\n    s.last<\/span>=<span style=\"color: #000000;\">p;\n    <\/span><span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">;\n}\n<\/span><span style=\"color: #0000ff;\">int<\/span> dequeue(linkqueue &amp;s,<span style=\"color: #0000ff;\">int<\/span> &amp;e){<span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u51fa<\/span>\n    <span style=\"color: #0000ff;\">if<\/span>(s.first==s.last)<span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #800080;\">0<\/span><span style=\"color: #000000;\">;\n    queueptr p<\/span>=s.first-&gt;<span style=\"color: #000000;\">next;\n    e<\/span>=p-&gt;<span style=\"color: #000000;\">data;\n    s.first<\/span>-&gt;next=p-&gt;<span style=\"color: #000000;\">next;\n    <\/span><span style=\"color: #0000ff;\">if<\/span>(s.last==p)s.last=<span style=\"color: #000000;\">s.first;\n    <\/span><span style=\"color: #0000ff;\">free<\/span><span style=\"color: #000000;\">(p);\n    <\/span><span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">;\n}\n<\/span><span style=\"color: #0000ff;\">int<\/span> destroyquenue(linkqueue &amp;s){<span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u6bc1\u961f<\/span>\n    <span style=\"color: #0000ff;\">while<\/span><span style=\"color: #000000;\">(s.first){\n        s.last<\/span>=s.first-&gt;<span style=\"color: #000000;\">next;\n        <\/span><span style=\"color: #0000ff;\">free<\/span><span style=\"color: #000000;\">(s.first);\n        s.first<\/span>=<span style=\"color: #000000;\">s.last;\n    }\n    <\/span><span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">;\n}\n\n<\/span><span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u5faa\u73af\u5217\u961f<\/span>\n<span style=\"color: #0000ff;\">#define<\/span> maxsize 100<span style=\"color: #000000;\">\ntypedef <\/span><span style=\"color: #0000ff;\">struct<\/span><span style=\"color: #000000;\">{\n    <\/span><span style=\"color: #0000ff;\">int<\/span> *<span style=\"color: #0000ff;\">base<\/span><span style=\"color: #000000;\">;\n    <\/span><span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\"> front,rear;\n}sqquenue;\n<\/span><span style=\"color: #0000ff;\">int<\/span> intiquenue(sqquenue &amp;s){<span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u5efa<\/span>\n    s.<span style=\"color: #0000ff;\">base<\/span>=(<span style=\"color: #0000ff;\">int<\/span> *)<span style=\"color: #0000ff;\">malloc<\/span>(maxsize*<span style=\"color: #0000ff;\">sizeof<\/span>(<span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\">));\n    <\/span><span style=\"color: #0000ff;\">if<\/span>(!s.<span style=\"color: #0000ff;\">base<\/span>)exit(-<span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">);\n    s.front<\/span>=s.rear=<span style=\"color: #800080;\">0<\/span><span style=\"color: #000000;\">;\n    <\/span><span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">;\n}\n<\/span><span style=\"color: #0000ff;\">int<\/span> quenuelen(sqquenue &amp;s){<span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u957f\u5ea6<\/span>\n    <span style=\"color: #0000ff;\">return<\/span>(s.rear-s.front+maxsize)%<span style=\"color: #000000;\">maxsize;\n}\n<\/span><span style=\"color: #0000ff;\">int<\/span> enqueue(sqquenue &amp;s,<span style=\"color: #0000ff;\">int<\/span> e){<span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u63d2\u5165<\/span>\n    <span style=\"color: #0000ff;\">if<\/span>((s.rear+<span style=\"color: #800080;\">1<\/span>)%maxsize==s.front)<span style=\"color: #0000ff;\">return<\/span> -<span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">;\n    s.<\/span><span style=\"color: #0000ff;\">base<\/span>[s.rear]=<span style=\"color: #000000;\">e;\n    s.rear<\/span>=(s.rear+<span style=\"color: #800080;\">1<\/span>)%<span style=\"color: #000000;\">maxsize;\n    <\/span><span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">;\n}\n<\/span><span style=\"color: #0000ff;\">int<\/span> dequenue(sqquenue &amp;s){<span style=\"color: #008000;\">\/\/<\/span><span style=\"color: #008000;\">\u5220<\/span>\n    <span style=\"color: #0000ff;\">if<\/span>(s.front==s.rear)<span style=\"color: #0000ff;\">return<\/span> -<span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">;\n    s.front<\/span>=(s.front+<span style=\"color: #800080;\">1<\/span>)%<span style=\"color: #000000;\">maxsize;\n    <\/span><span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">;\n}<\/span><\/pre>\n<\/div>\n<p>\u6808\u548c\u5217\u961f\u7684\u4e00\u4e9b\u4ee3\u7801<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;iostream&gt; #include &lt;cstdio&gt;  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-186","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6808\u548c\u5217\u961f - imwarming<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/imwarming.com\/?p=186\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6808\u548c\u5217\u961f - imwarming\" \/>\n<meta property=\"og:description\" content=\"#include &lt;iostream&gt; #include &lt;cstdio&gt; [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/imwarming.com\/?p=186\" \/>\n<meta property=\"og:site_name\" content=\"imwarming\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-05T09:02:00+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"warming\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/imwarming.com\/#website\",\"url\":\"https:\/\/imwarming.com\/\",\"name\":\"imwarming\",\"description\":\"\u6c38\u8fdc\u5e74\u8f7b\uff0c\u6c38\u8fdc\u70ed\u6cea\u76c8\u7736\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/imwarming.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/imwarming.com\/?p=186#webpage\",\"url\":\"https:\/\/imwarming.com\/?p=186\",\"name\":\"\u6808\u548c\u5217\u961f - imwarming\",\"isPartOf\":{\"@id\":\"https:\/\/imwarming.com\/#website\"},\"datePublished\":\"2019-11-05T09:02:00+00:00\",\"dateModified\":\"2019-11-05T09:02:00+00:00\",\"author\":{\"@id\":\"https:\/\/imwarming.com\/#\/schema\/person\/9d76869a558bac6dd0d6d58f420ee8ea\"},\"breadcrumb\":{\"@id\":\"https:\/\/imwarming.com\/?p=186#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/imwarming.com\/?p=186\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/imwarming.com\/?p=186#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/imwarming.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6808\u548c\u5217\u961f\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/imwarming.com\/#\/schema\/person\/9d76869a558bac6dd0d6d58f420ee8ea\",\"name\":\"warming\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/imwarming.com\/#personlogo\",\"inLanguage\":\"zh-Hans\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c4a913eed88f7601b76bbf2b103472621195b6fa2f742af89b5ea185b60e7cff?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c4a913eed88f7601b76bbf2b103472621195b6fa2f742af89b5ea185b60e7cff?s=96&d=mm&r=g\",\"caption\":\"warming\"},\"sameAs\":[\"https:\/\/imwarming.com\"],\"url\":\"https:\/\/imwarming.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u6808\u548c\u5217\u961f - imwarming","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/imwarming.com\/?p=186","og_locale":"zh_CN","og_type":"article","og_title":"\u6808\u548c\u5217\u961f - imwarming","og_description":"#include &lt;iostream&gt; #include &lt;cstdio&gt; [&hellip;]","og_url":"https:\/\/imwarming.com\/?p=186","og_site_name":"imwarming","article_published_time":"2019-11-05T09:02:00+00:00","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"warming","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/imwarming.com\/#website","url":"https:\/\/imwarming.com\/","name":"imwarming","description":"\u6c38\u8fdc\u5e74\u8f7b\uff0c\u6c38\u8fdc\u70ed\u6cea\u76c8\u7736","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/imwarming.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"https:\/\/imwarming.com\/?p=186#webpage","url":"https:\/\/imwarming.com\/?p=186","name":"\u6808\u548c\u5217\u961f - imwarming","isPartOf":{"@id":"https:\/\/imwarming.com\/#website"},"datePublished":"2019-11-05T09:02:00+00:00","dateModified":"2019-11-05T09:02:00+00:00","author":{"@id":"https:\/\/imwarming.com\/#\/schema\/person\/9d76869a558bac6dd0d6d58f420ee8ea"},"breadcrumb":{"@id":"https:\/\/imwarming.com\/?p=186#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/imwarming.com\/?p=186"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/imwarming.com\/?p=186#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/imwarming.com\/"},{"@type":"ListItem","position":2,"name":"\u6808\u548c\u5217\u961f"}]},{"@type":"Person","@id":"https:\/\/imwarming.com\/#\/schema\/person\/9d76869a558bac6dd0d6d58f420ee8ea","name":"warming","image":{"@type":"ImageObject","@id":"https:\/\/imwarming.com\/#personlogo","inLanguage":"zh-Hans","url":"https:\/\/secure.gravatar.com\/avatar\/c4a913eed88f7601b76bbf2b103472621195b6fa2f742af89b5ea185b60e7cff?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c4a913eed88f7601b76bbf2b103472621195b6fa2f742af89b5ea185b60e7cff?s=96&d=mm&r=g","caption":"warming"},"sameAs":["https:\/\/imwarming.com"],"url":"https:\/\/imwarming.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/posts\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imwarming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=186"}],"version-history":[{"count":0,"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions"}],"wp:attachment":[{"href":"https:\/\/imwarming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imwarming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imwarming.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}