{"id":49,"date":"2013-10-25T14:38:24","date_gmt":"2013-10-25T14:38:24","guid":{"rendered":""},"modified":"2013-10-25T14:38:24","modified_gmt":"2013-10-25T14:38:24","slug":"","status":"publish","type":"post","link":"http:\/\/weizn.net\/?p=49","title":{"rendered":"Stack"},"content":{"rendered":"<p>#include &lt;iostream&gt;<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<\/p>\n<p>#define ElemType int<\/p>\n<p>using namespace std;<\/p>\n<p>typedef struct<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; ElemType *top;<br \/>\n&nbsp;&nbsp;&nbsp; ElemType *base;<br \/>\n&nbsp;&nbsp;&nbsp; int Stacksize;<br \/>\n} Stack;<\/p>\n<p>bool InitStack(Stack &amp;S)<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; if((S.base=(ElemType *)malloc(5*sizeof(ElemType)))==NULL) return false;<br \/>\n&nbsp;&nbsp;&nbsp; S.top=S.base;<br \/>\n&nbsp;&nbsp;&nbsp; S.Stacksize=5;<br \/>\n&nbsp;&nbsp;&nbsp; return true;<br \/>\n}<\/p>\n<p>bool Push(Stack &amp;S,ElemType e)<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; if(S.top-S.base==S.Stacksize-1)<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if((S.base=(ElemType *)realloc(S.base,++S.Stacksize*sizeof(ElemType)))==NULL)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S.top=S.base+S.Stacksize-2;<br \/>\n&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp; *S.top++=e;<br \/>\n&nbsp;&nbsp;&nbsp; return true;<br \/>\n}<\/p>\n<p>bool Pop(Stack &amp;S,ElemType &amp;e)<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; if(S.top-S.base==0) return false;<br \/>\n&nbsp;&nbsp;&nbsp; e=*&#8211;S.top;<br \/>\n&nbsp;&nbsp;&nbsp; return true;<br \/>\n}<\/p>\n<p>bool StackEmpty(Stack &amp;S)<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; if(S.top-S.base==0) return true;<br \/>\n&nbsp;&nbsp;&nbsp; return false;<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; Stack S;<br \/>\n&nbsp;&nbsp;&nbsp; ElemType e;<br \/>\n&nbsp;&nbsp;&nbsp; int decimal,radix;<\/p>\n<p>&nbsp;&nbsp;&nbsp; if(!InitStack(S)) return -1;<br \/>\n&nbsp;&nbsp;&nbsp; cout &lt;&lt;&#8220;\u8bf7\u8f93\u5165\u5341\u8fdb\u5236\u6574\u6570\u548c\u8981\u8f6c\u6362\u7684\u8fdb\u5236:&#8221;;<br \/>\n&nbsp;&nbsp;&nbsp; if(scanf(&#8220;%d%d&#8221;,&amp;decimal,&amp;radix)!=2) return -1;<\/p>\n<p>&nbsp;&nbsp;&nbsp; while (decimal)<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Push(S,decimal%radix);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; decimal\/=radix;<br \/>\n&nbsp;&nbsp;&nbsp; }<\/p>\n<p>&nbsp;&nbsp;&nbsp; while(!StackEmpty(S))<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Pop(S,e);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt;e;<br \/>\n&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp; cout &lt;&lt;endl;<\/p>\n<p>&nbsp;&nbsp;&nbsp; return 0;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;iostream&gt;<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<\/p>\n<p>#define ElemType int<\/p>\n<p>using namespace std;<\/p>\n<p>typedef struct<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; ElemType *top;<br \/>\n&nbsp;&nbsp;&nbsp; ElemType *base&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[326],"tags":[],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Stack - Wayne&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/weizn.net\/?p=49\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Stack - Wayne&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"#include &lt;iostream&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt;#define ElemType intusing namespace std;typedef struct { &nbsp;&nbsp;&nbsp; ElemType *top; &nbsp;&nbsp;&nbsp; ElemType *base...\" \/>\n<meta property=\"og:url\" content=\"http:\/\/weizn.net\/?p=49\" \/>\n<meta property=\"og:site_name\" content=\"Wayne&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2013-10-25T14:38:24+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=\"zinan\" \/>\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\":\"http:\/\/weizn.net\/#website\",\"url\":\"http:\/\/weizn.net\/\",\"name\":\"Wayne&#039;s Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/weizn.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/weizn.net\/?p=49#webpage\",\"url\":\"http:\/\/weizn.net\/?p=49\",\"name\":\"Stack - Wayne&#039;s Blog\",\"isPartOf\":{\"@id\":\"http:\/\/weizn.net\/#website\"},\"datePublished\":\"2013-10-25T14:38:24+00:00\",\"dateModified\":\"2013-10-25T14:38:24+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/weizn.net\/?p=49#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/weizn.net\/?p=49\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/weizn.net\/?p=49#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\\u9996\\u9875\",\"item\":\"http:\/\/weizn.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Stack\"}]},{\"@type\":\"Article\",\"@id\":\"http:\/\/weizn.net\/?p=49#article\",\"isPartOf\":{\"@id\":\"http:\/\/weizn.net\/?p=49#webpage\"},\"author\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"headline\":\"Stack\",\"datePublished\":\"2013-10-25T14:38:24+00:00\",\"dateModified\":\"2013-10-25T14:38:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/weizn.net\/?p=49#webpage\"},\"wordCount\":319,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"articleSection\":[\"\\u6570\\u636e\\u7ed3\\u6784\\u53ca\\u7b97\\u6cd5\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/weizn.net\/?p=49#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\",\"name\":\"zinan\",\"logo\":{\"@id\":\"http:\/\/weizn.net\/#personlogo\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Stack - Wayne&#039;s Blog","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":"http:\/\/weizn.net\/?p=49","og_locale":"zh_CN","og_type":"article","og_title":"Stack - Wayne&#039;s Blog","og_description":"#include &lt;iostream&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt;#define ElemType intusing namespace std;typedef struct { &nbsp;&nbsp;&nbsp; ElemType *top; &nbsp;&nbsp;&nbsp; ElemType *base...","og_url":"http:\/\/weizn.net\/?p=49","og_site_name":"Wayne&#039;s Blog","article_published_time":"2013-10-25T14:38:24+00:00","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"zinan","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"http:\/\/weizn.net\/#website","url":"http:\/\/weizn.net\/","name":"Wayne&#039;s Blog","description":"","publisher":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/weizn.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"http:\/\/weizn.net\/?p=49#webpage","url":"http:\/\/weizn.net\/?p=49","name":"Stack - Wayne&#039;s Blog","isPartOf":{"@id":"http:\/\/weizn.net\/#website"},"datePublished":"2013-10-25T14:38:24+00:00","dateModified":"2013-10-25T14:38:24+00:00","breadcrumb":{"@id":"http:\/\/weizn.net\/?p=49#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/weizn.net\/?p=49"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/weizn.net\/?p=49#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/weizn.net\/"},{"@type":"ListItem","position":2,"name":"Stack"}]},{"@type":"Article","@id":"http:\/\/weizn.net\/?p=49#article","isPartOf":{"@id":"http:\/\/weizn.net\/?p=49#webpage"},"author":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"headline":"Stack","datePublished":"2013-10-25T14:38:24+00:00","dateModified":"2013-10-25T14:38:24+00:00","mainEntityOfPage":{"@id":"http:\/\/weizn.net\/?p=49#webpage"},"wordCount":319,"commentCount":0,"publisher":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"articleSection":["\u6570\u636e\u7ed3\u6784\u53ca\u7b97\u6cd5"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/weizn.net\/?p=49#respond"]}]},{"@type":["Person","Organization"],"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264","name":"zinan","logo":{"@id":"http:\/\/weizn.net\/#personlogo"}}]}},"_links":{"self":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=49"}],"version-history":[{"count":0,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts\/49\/revisions"}],"wp:attachment":[{"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}