STL学习笔记——1.queue

论坛 期权论坛     
选择匿名的用户   2021-6-2 15:38   229   0
<p><span style="font-family:Calibri; font-size:14px">STL</span><span style="font-size:14px">学习笔记——</span><span style="font-family:Calibri; font-size:14px">1.queue</span></p>
<p><span style="font-family:Calibri; font-size:14px">     </span><span style="font-size:14px">之前被学长坑了,非要模拟队列,以至于现在完全看不懂网上用</span><span style="font-family:Calibri; font-size:14px">STL</span><span style="font-size:14px">写的代码,只有现学了</span><span style="font-family:Calibri; font-size:14px">(</span><span style="font-size:14px">╯‵□′</span><span style="font-family:Calibri; font-size:14px">)</span><span style="font-size:14px">╯︵┻━┻。</span></p>
<p><span style="font-size:14px">以下资料主要参考网站</span><span style="font-family:Calibri; font-size:14px">http://www.cplusplus.com/reference/queue/</span></p>
<p align="left" style="background:white"><span style="color:black">classtemplate </span> </p>
<p align="right" style="background:white"><span style="color:black">&lt;queue&gt;</span></p>
<div style="background:white">
<p align="left" style="background:white"><strong><span style="color:rgb(80,80,160)">std::</span><span style="color:black">queue</span></strong></p>
</div>
<p align="left" style="background:rgb(250,255,250)"><span style="color:green">template &lt;class T, class Container &#61;deque&lt;T&gt; &gt; class queue;</span></p>
<p align="left" style="background:white"><strong><span style="color:black">FIFOqueue</span></strong></p>
<p align="left" style="background:white"><strong><span style="color:black">queue</span></strong><span style="color:black">s area type of container adaptor, specifically designed to operate in a FIFO context(first-in first-out), where elements are inserted into one end of the containerand extracted from the other.<br> <strong>queue</strong>s are implemented as <em>containers adaptors</em>, which are classesthat use an encapsulated object of a specific container class as its <em>underlyingcontainer</em>, providing a specific set of member functions to access itselements. Elements are <em>pushed</em> into the <em>&#34;back&#34;</em> of thespecific container and <em>popped</em> from its <em>&#34;front&#34;</em>.<br> The underlying container may be one of the standard container class template orsome other specifically designed container class. This underlying containershall support at least the following operations:</span></p>
<ul type="disc"><li style="background:white; color:black">empty </li><li style="background:white; color:black">size </li><li style="background:white; color:black">front </li><li style="background:white; color:black">back </li><li style="background:white; color:black">push_back </li><li style="background:white; color:black">pop_front</li></ul>
<p>队列的特点如上文,简单而言就是<span style="font-family:Calibri">FIFO</span>,即<span style="background:yellow"><span style="font-family:Calibri">F</span></span><span style="font-family:Calibri">irst </span><span style="background:yellow"><span style="font-family:Calibri">I</span></span><span style="font-family:Calibri">n </span><span style="background:yellow"><span style="font-family:Calibri">F</span></span><span style="font-family:Calibri">irst </span><span style="background:yellow"><span style="font-family:Calibri">O</span></span><span style="font-family:Calibri">ut</span>,也就是先入先出。主要形式要注意:</p>
<p><span style="font-family:Calibri">●</span>头文件<span style="font-family:Calibri"> #include&lt;queue&gt;(</span>或者直接写<span style="font-family:Calibri">#include&lt;bits/stdc&#43;&#43;.h&gt;)</span></p>
<p><span style="font-family:Calibri">●</span>声明:</p>
<p><span style="font-family:Calibri"></span>如果之前已经声明了命名空间:<span style="font-family:Calibri">using namespace std;</span></p>
<p>则直接写:<span style="font-family:Calibri">queue&lt;</span>变量类型(如<span style="font-family:Calibri">int||char</span>)<span style="font-family:Calibri">&gt; </span>变量名称(选一个自己喜欢的就好罒ω罒)</p>
<p><span style="font-family:Calibri"></span>如果之前没有声明命名空间,则写:</p>
<p><span style="font-family:Calibri">std::queue&lt;</span>变量类型(如<span style="font-family:Calibri">int||char</span>)<span style="font-family:Calibri">&gt; </span>变量名称(选一个自己喜欢的就好罒ω罒)</p>
<p><span style="font-family:Calibri">●</span>常用函数:</p>
<p><span style="font-family:Calibri">                   </span><span style="font-family:Calibri">empty:</span></p>
<div style="background:white">
<p align="left" style="background:white"><strong><span style="color:rgb(80,80,160)">std::</span></strong><a href="http://www.cplusplus.com/reference/queue/queue/" rel="noopener noreferrer" target="_blank"><strong><span style="color:rgb(0,0,112)">queue</span></strong></a><strong><span style="color:black">::empty</span></strong></p>
</div>
<p align="left" style="background:rgb(250,255,250)"><span style="color:green">bool empty() const;</span></p>
<p align="left" style="background:white"><strong><span style="color:black">Test whethercontainer is empty</span></strong></p>
<p align="left" style="background:white"><span style="color:black">Ret
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP