499-500.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 144 行

HTML
144
字号
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:Programming in C&#43;&#43;</TITLE>

<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0672313723//-->

<!--TITLE=Linux Unleashed, Third Edition//-->

<!--AUTHOR=Tim Parker//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Sams//-->

<!--CHAPTER=27//-->

<!--PAGES=499-500//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="497-499.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="500-502.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading19"></A><FONT COLOR="#000077">Stacks</FONT></H4>

<P>The <TT>Stacks</TT> class implements the standard version of a last-in-first-out (LIFO) stack. Three different implementations of stacks are offered by the GNU C&#43;&#43; class library: <TT>the VStack</TT>, the <TT>XPStack</TT>, and the <TT>SLStack</TT>. The <TT>VStack</TT> is a fixed-size stack, meaning that you must specify an upper bound on the size of the stack when you first create it. The <TT>XPStack</TT> and the <TT>SLStack</TT> are both dynamically sized stacks that are implemented in a slightly different way.</P>

<P>Table 27.8 lists the operations that can be performed on the <TT>Stacks</TT> classes.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 27.8.</B> <TT>Stack</TT> class operators.

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH WIDTH="40%" ALIGN="LEFT">Operator

<TH WIDTH="60%" ALIGN="LEFT">Description

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD><TT>Stack st</TT>

<TD>Declares <TT>st</TT> to be a stack

<TR>

<TD><TT>Stack st(sz)</TT>

<TD>Declares <TT>st</TT> to be a stack of size <TT>sz</TT>

<TR>

<TD><TT>st.empty()</TT>

<TD>Returns <TT>TRUE</TT> if <TT>stack</TT> is empty

<TR>

<TD><TT>st.full()</TT>

<TD>Returns <TT>TRUE</TT> if <TT>stack</TT> is full

<TR>

<TD><TT>st.length()</TT>

<TD>Returns the number of elements in <TT>stack</TT>

<TR>

<TD><TT>st.push(<I>x</I>)</TT>

<TD>Puts element <I>x</I> onto the top of the stack

<TR>

<TD VALIGN="TOP"><TT><I>x</I>= st.pop()</TT>

<TD>Removes and returns the top element from the stack

<TR>

<TD><TT>st.top()</TT>

<TD>Returns a pointer to the top element in the stack

<TR>

<TD VALIGN="TOP"><TT>st.del_top()</TT>

<TD>Deletes the top element from the stack without returning it

<TR>

<TD><TT>st.clear()</TT>

<TD>Deletes all elements from <TT>stack

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<H4 ALIGN="LEFT"><A NAME="Heading20"></A><FONT COLOR="#000077">Queues</FONT></H4>

<P>The <TT>Queue</TT> class implements a standard version of a first-in-first-out (FIFO) queue. Three different kinds of queue are provided by the GNU C&#43;&#43; class library: the <TT>VQueue</TT>, the <TT>XPQueue</TT>, and the <TT>SLQueue</TT>. The <TT>VQueue</TT> is a fixed-size queue, so you must specify an upper bound on the size of this kind of queue when you first create it. The <TT>XPQueue</TT> and the <TT>SLQueue</TT> are both dynamically sized queues, so no upper bound is required. The operations supported by the <TT>Queue</TT> classes are listed in Table 27.9.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 27.9.</B> <TT>Queue</TT> class operators.

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH WIDTH="40%" ALIGN="LEFT">Operator

<TH WIDTH="60%" ALIGN="LEFT">Description

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD><TT>Queue q</TT>

<TD>Declares <TT>q</TT> to be a queue

<TR>

<TD><TT>Queue q(<I>sz</I>)</TT>

<TD>Declares <TT>q</TT> to be a queue of size <I>sz</I>

<TR>

<TD><TT>q.empty()</TT>

<TD>Returns <TT>TRUE</TT> if <TT>q</TT> is empty

<TR>

<TD><TT>q.full()</TT>

<TD>Returns <TT>TRUE</TT> if <TT>q</TT> is full

<TR>

<TD><TT>q.length()</TT>

<TD>Returns the number of elements in <TT>q</TT>

<TR>

<TD><TT>q.enq(<I>x</I>)</TT>

<TD>Adds the <I>x</I> element to <TT>q</TT>

<TR>

<TD><TT><I>x</I>= q.deq()</TT>

<TD>Removes and returns an element from <TT>q</TT>

<TR>

<TD><TT>q.front()</TT>

<TD>Returns a pointer to the front of <TT>q</TT>

<TR>

<TD VALIGN="TOP"><TT>q.del_front()</TT>

<TD>Removes an element from <TT>q</TT> and does not return the result

<TR>

<TD><TT>q.clear</TT>

<TD>Removes all elements from the queue

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P>In addition to the normal kind of queue that is discussed in this section, the GNU C&#43;&#43; class library also supports double-ended queues and priority queues. Both of these types of queues have similar behavior to the regular queue. The double-ended queue adds operators for returning a pointer to the rear of the queue and deleting elements from the rear of the queue. The priority queues are arranged so that a user has fast access to the least element in the queue. They support additional operators that allow for searching for elements in the queue.

</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="497-499.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="500-502.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?