{"id":430,"date":"2010-04-25T00:23:34","date_gmt":"2010-04-24T16:23:34","guid":{"rendered":"http:\/\/115.29.108.60\/?p=430"},"modified":"2010-04-25T01:02:32","modified_gmt":"2010-04-24T17:02:32","slug":"c-primer-chapter9","status":"publish","type":"post","link":"http:\/\/115.29.108.60\/?p=430","title":{"rendered":"C++ Primer Chapter9"},"content":{"rendered":"<p>1\u3001\u5bb9\u5668\u7684\u5bb9\u5668vector&lt; vector&lt;string&gt; &gt; lines;\u5fc5\u987b\u7528\u7a7a\u683c\u9694\u5f00\u4e24\u4e2a\u76f8\u90bb\u7684&gt;\u7b26\u53f7\uff0c\u4ee5\u793a\u8fd9\u662f\u4e24\u4e2a\u5206\u5f00\u7684\u7b26\u53f7\uff0c\u5426\u5219\uff0c\u7cfb\u7edf\u4f1a\u8ba4\u4e3a&gt;&gt;\u662f\u5355\u4e2a\u7b26\u53f7\uff0c\u4e3a\u53f3\u79fb\u64cd\u4f5c\u7b26\uff0c\u5e76\u7ed3\u679c\u5bfc\u81f4\u7f16\u8bd1\u65f6\u9519\u8bef\u3002<\/p>\n<p>2\u3001\u4f7f\u7528\u8fed\u4ee3\u5668\u7f16\u5199\u7a0b\u5e8f\u65f6\uff0c\u5fc5\u987b\u7559\u610f\u54ea\u4e9b\u64cd\u4f5c\u4f1a\u4f7f\u8fed\u4ee3\u5668\u5931\u6548\u3002\u4f7f\u7528\u65e0\u6548\u8fed\u4ee3\u5668\u5c06\u4f1a\u5bfc\u81f4\u4e25\u91cd\u7684\u8fd0\u884c\u65f6\u9519\u8bef\u3002<\/p>\n<p>3\u3001\u5bb9\u5668\u5b9a\u4e49\u7684\u7c7b\u578b\u522b\u540d\uff1a<\/p>\n<p>size_type \u65e0\u7b26\u53f7\u6574\u578b\uff0c\u8db3\u4ee5\u5b58\u50a8\u6b64\u5bb9\u5668\u7c7b\u578b\u7684\u6700\u5927\u53ef\u80fd\u5bb9\u5668\u957f\u5ea6<\/p>\n<p>iterator \u6b64\u5bb9\u5668\u7c7b\u578b\u7684\u8fed\u4ee3\u5668<\/p>\n<p>const_iterator \u5143\u7d20\u7684\u53ea\u8bfb\u8fed\u4ee3\u5668\u7c7b\u578b<\/p>\n<p>reverse_iterator \u6309\u9006\u5e8f\u5bfb\u5740\u5143\u7d20\u7684\u8fed\u4ee3\u5668<\/p>\n<p>const_reverse_iterator \u5143\u7d20\u7684\u53ea\u8bfb\uff08\u4e0d\u80fd\u5199\uff09\u9006\u5e8f\u8fed\u4ee3\u5668<\/p>\n<p>difference_type \u8db3\u591f\u5b58\u50a8\u4e24\u4e2a\u8fed\u4ee3\u5668\u5dee\u503c\u7684\u6709\u7b26\u53f7\u6574\u578b\uff0c\u53ef\u4e3a\u8d1f\u6570<\/p>\n<p>value_type \u5143\u7d20\u7c7b\u578b<\/p>\n<p>reference \u5143\u7d20\u7684\u5de6\u503c\u7c7b\u578b\uff0c\u662fvalue_type&amp;\u7684\u540c\u4e49\u8bcd<\/p>\n<p>const_referenct \u5143\u7d20\u7684\u5e38\u91cf\u5de6\u503c\u7c7b\u578b\uff0c\u7b49\u6548\u4e8econst value_type&amp;<\/p>\n<p>4\u3001\u5728\u987a\u5e8f\u5bb9\u5668\u4e2d\u6dfb\u52a0\u5143\u7d20\uff1a<\/p>\n<p>push_back<\/p>\n<p>push_front \u53ea\u9002\u7528\u4e8elist\u548cdeque\u5bb9\u5668\u7c7b\u578b<\/p>\n<p>insert<\/p>\n<p>5\u3001\u8bbf\u95ee\u5143\u7d20\uff1a<\/p>\n<p>c.back()<\/p>\n<p>c.front()<\/p>\n<p>c[n] \u53ea\u9002\u7528\u4e8evector\u548cdeque\u5bb9\u5668<\/p>\n<p>c.at(n) \u53ea\u9002\u7528\u4e8evector\u548cdeque\u5bb9\u5668<\/p>\n<p>6\u3001\u5220\u9664\u5143\u7d20\uff1a<\/p>\n<p>erase<\/p>\n<p>clear<\/p>\n<p>pop_back<\/p>\n<p>pop_front \u53ea\u9002\u7528\u4e8elist\u6216deque\u5bb9\u5668<\/p>\n<p>7\u3001\u987a\u5e8f\u5bb9\u5668\u7684\u8d4b\u503c\u64cd\u4f5c\uff1a<\/p>\n<p>c1 = c2 \u5220\u9664\u5bb9\u5668c1\u7684\u6240\u6709\u5143\u7d20\uff0c\u7136\u540e\u5c06c2\u7684\u5143\u7d20\u590d\u5236\u7ed9c1\u3002c1\u548cc2\u7684\u7c7b\u578b\uff08\u5305\u62ec\u5bb9\u5668\u7c7b\u578b\u548c\u5143\u7d20\u7c7b\u578b\uff09\u5fc5\u987b\u76f8\u540c<\/p>\n<p>c1.swap(c2) \u4ea4\u6362\u5185\u5bb9\uff1a\u8c03\u7528\u5b8c\u8be5\u51fd\u6570\u540e\uff0cc1\u4e2d\u5b58\u653e\u7684\u662fc2\u539f\u6765\u7684\u5143\u7d20\uff0cc2\u4e2d\u5b58\u653e\u7684\u5219\u662fc1\u539f\u6765\u7684\u5143\u7d20\u3002c1\u548cc2\u7684\u7c7b\u578b\u5fc5\u987b\u76f8\u540c\u3002\u8be5\u51fd\u6570\u7684\u6267\u884c\u901f\u5ea6\u901a\u5e38\u8981\u6bd4\u5c06c2\u7684\u5143\u7d20\u590d\u5236\u5230c1\u7684\u64cd\u4f5c\u5feb<\/p>\n<p>c.assign(b, e) \u91cd\u65b0\u8bbe\u7f6ec\u7684\u5143\u7d20\uff1a\u5c06\u8fed\u4ee3\u5668b\u548ce\u6807\u8bb0\u7684\u8303\u56f4\u5185\u6240\u6709\u7684\u5143\u7d20\u590d\u5236\u5230c\u4e2d\u3002b\u548ce\u5fc5\u987b\u4e0d\u662f\u6307\u5411c\u4e2d\u5143\u7d20\u7684\u8fed\u4ee3\u5668\u3002<\/p>\n<p>c.assign(n, t) \u5c06\u5bb9\u5668c\u91cd\u65b0\u8bbe\u7f6e\u4e3a\u5b58\u50a8n\u4e2a\u503c\u4e3at\u7684\u5143\u7d20<\/p>\n<p>\u5982\u679c\u5728\u4e0d\u540c\uff08\u6216\u76f8\u540c\uff09\u7c7b\u578b\u7684\u5bb9\u5668\u5185\uff0c\u5143\u7d20\u7c7b\u578b\u4e0d\u76f8\u540c\u4f46\u662f\u76f8\u4e92\u517c\u5bb9\uff0c\u5219\u5176\u8d4b\u503c\u8fd0\u7b97\u5fc5\u987b\u4f7f\u7528assign\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u53ef\u901a\u8fc7assign\u64cd\u4f5c\u5b9e\u73b0\u5c06vector\u5bb9\u5668\u4e2d\u4e00\u6bb5char*\u7c7b\u578b\u7684\u5143\u7d20\u8d4b\u7ed9string\u7c7b\u578b\u7684list\u5bb9\u5668\u3002<\/p>\n<p>\u7531\u4e8eassign\u64cd\u4f5c\u9996\u5148\u5220\u9664\u5bb9\u5668\u4e2d\u539f\u6765\u5b58\u50a8\u7684\u6240\u6709\u5143\u7d20\uff0c\u56e0\u6b64\uff0c\u4f20\u9012\u7ed9assign\u51fd\u6570\u7684\u8fed\u4ee3\u5668\u4e0d\u80fd\u6307\u5411\u8c03\u7528\u8be5\u51fd\u6570\u7684\u5bb9\u5668\u5185\u5143\u7d20\u3002<\/p>\n<p>8\u3001vector\u7c7b\u63d0\u4f9b\u4e86\u4e24\u4e2a\u6210\u5458\u51fd\u6570\uff1acapacity\u548creserve\uff0c\u4f7f\u7a0b\u5e8f\u5458\u53ef\u4e0evector\u5bb9\u5668\u5185\u5b58\u5206\u8d1d\u7684\u5b9e\u73b0\u90e8\u5206\u4ea4\u4e92\u5de5\u4f5c\u3002capacity\u64cd\u4f5c\u83b7\u53d6\u5bb9\u5668\u9700\u8981\u5206\u914d\u66f4\u591a\u7684\u5b58\u50a8\u7a7a\u95f4\u4e4b\u524d\u80fd\u591f\u5b58\u50a8\u7684\u5143\u7d20\u603b\u6570\uff0c\u800creserve\u64cd\u4f5c\u5219\u544a\u8bc9vector\u5bb9\u5668\u5e94\u8be5\u9884\u7559\u591a\u5c11\u4e2a\u5143\u7d20\u7684\u5b58\u50a8\u7a7a\u95f4\u3002<\/p>\n<p>9\u3001\u672c\u8d28\u4e0a\uff0c\u9002\u914d\u5668\u662f\u4f7f\u4e00\u4e8b\u7269\u7684\u884c\u4e3a\u7c7b\u4f3c\u4e8e\u53e6\u4e00\u4e8b\u7269\u7684\u884c\u4e3a\u7684\u4e00\u79cd\u673a\u5236\u3002\u5bb9\u5668\u9002\u914d\u5668\u8ba9\u4e00\u79cd\u5df2\u5b58\u5728\u7684\u5bb9\u5668\u7c7b\u578b\u91c7\u7528\u53e6\u4e00\u79cd\u4e0d\u540c\u7684\u62bd\u8c61\u7c7b\u578b\u7684\u5de5\u4f5c\u65b9\u5f0f\u5b9e\u73b0\u3002\u4f8b\u5982\uff0cstack\uff08\u6808\uff09\u9002\u914d\u5668\u53ef\u4f7f\u4efb\u4f55\u4e00\u79cd\u987a\u5e8f\u5bb9\u5668\u4ee5\u6808\u7684\u65b9\u5f0f\u5de5\u4f5c\u3002<\/p>\n<p>\u9ed8\u8ba4\u7684stack\u548cqueue\u90fd\u57fa\u4e8edeque\u5bb9\u5668\u5b9e\u73b0\uff0c\u800cpriority_queue\u5219\u5728vector\u5bb9\u5668\u4e0a\u5b9e\u73b0\u3002\u5728\u521b\u5efa\u9002\u914d\u5668\u65f6\uff0c\u901a\u8fc7\u5c06\u4e00\u4e2a\u987a\u5e8f\u5bb9\u5668\u6307\u5b9a\u4e3a\u9002\u914d\u5668\u7684\u7b2c\u4e8c\u4e2a\u7c7b\u578b\u5b9e\u53c2\uff0c\u53ef\u8986\u76d6\u5176\u5173\u8054\u7684\u57fa\u7840\u5bb9\u5668\u7c7b\u578b\uff1a<\/p>\n<p>stack&lt; string, vector&lt;string&gt; &gt; str_stk;\u00a0\u00a0\u00a0 \/\/ \u4f7fstack\u57fa\u4e8evector\u5b9e\u73b0<\/p>\n<p>\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u9002\u914d\u5668\uff0c\u5176\u5173\u8054\u7684\u5bb9\u5668\u5fc5\u987b\u6ee1\u8db3\u4e00\u5b9a\u7684\u7ea6\u675f\u6761\u4ef6\u3002stack\u9002\u914d\u5668\u6240\u5173\u8054\u7684\u57fa\u7840\u5bb9\u5668\u53ef\u4ee5\u662f\u4efb\u610f\u4e00\u79cd\u987a\u5e8f\u5bb9\u5668\u7c7b\u578b\u3002\u56e0\u6b64\uff0cstack\u6808\u53ef\u4ee5\u5efa\u7acb\u5728vector\u3001list\u6216\u8005deque\u5bb9\u5668\u4e4b\u4e0a\u3002\u800cqueue\u9002\u914d\u5668\u8981\u6c42\u5176\u5173\u8054\u7684\u57fa\u7840\u5bb9\u5668\u5fc5\u987b\u63d0\u4f9bpush_front\u8fd0\u7b97\uff0c\u56e0\u6b64\u53ea\u80fd\u5efa\u7acb\u5728list\u6216\u8005deque\u5bb9\u5668\u4e0a\uff0c\u800c\u4e0d\u80fd\u5efa\u7acb\u5728vector\u5bb9\u5668\u4e0a\u3002priority_queue\u9002\u914d\u5668\u8981\u6c42\u63d0\u4f9b\u968f\u673a\u8bbf\u95ee\u529f\u80fd\uff0c\u56e0\u6b64\u53ef\u5efa\u7acb\u5728vector\u6216deque\u5bb9\u5668\u4e0a\uff0c\u4f46\u4e0d\u80fd\u5efa\u7acb\u5728list\u5bb9\u5668\u4e0a\u3002<\/p>\n<p>10\u3001\u6240\u6709\u9002\u914d\u5668\u90fd\u5b9a\u4e49\u4e86\u4e24\u4e2a\u6784\u9020\u51fd\u6570\uff1a\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\u7528\u4e8e\u521b\u5efa\u7a7a\u5bf9\u8c61\uff0c\u800c\u5e26\u4e00\u4e2a\u5bb9\u5668\u53c2\u6570\u7684\u6784\u9020\u51fd\u6570\u5c06\u53c2\u6570\u5bb9\u5668\u7684\u526f\u672c\u4f5c\u4e3a\u5176\u57fa\u7840\u503c\u3002\u4f8b\u5982\uff0c\u67b6\u8bbedeq\u662fdeque&lt;int&gt;\u7c7b\u578b\u7684\u5bb9\u5668\uff0c\u5219\u53ef\u7528deq\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u7684\u6808\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>stack&lt;int&gt; stk(deq);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u5bb9\u5668\u7684\u5bb9\u5668vector&lt; vector&lt;string&gt; &gt; lines;\u5fc5\u987b\u7528\u7a7a\u683c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-430","post","type-post","status-publish","format-standard","hentry","category-cplusplusprimer"],"_links":{"self":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=430"}],"version-history":[{"count":4,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/430\/revisions"}],"predecessor-version":[{"id":434,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/430\/revisions\/434"}],"wp:attachment":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=430"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}