page147.html

来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 54 行

HTML
54
字号
<HTML><HEAD><TITLE>Queues</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html2899" HREF="page148.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2897" HREF="page130.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2891" HREF="page146.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2901" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION006200000000000000000">Queues</A></H1><P>In the preceding section we saw that a stack comprises a pileof objects that can be accessed only at one end--the top.In this section we examine a similar data structure called a<em>single-ended queue</em><A NAME=5960>&#160;</A>.Whereas in a stack we add and remove elements at the same end of the pile,in a single-ended queue we add elements at one endand remove them from the other.Since it is always the first item to be put into the queuethat is the first item to be removed,a queue is a <em>first-in, first-out</em><A NAME=5962>&#160;</A>or <em>FIFO</em><A NAME=5964>&#160;</A> data structure.Figure&nbsp;<A HREF="page147.html#figqueue1"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> illustrates the basic queue operations.<P><P><A NAME="6234">&#160;</A><A NAME="figqueue1">&#160;</A> <IMG WIDTH=575 HEIGHT=200 ALIGN=BOTTOM ALT="figure5966" SRC="img687.gif"  ><BR><STRONG>Figure:</STRONG> Basic queue operations.<BR><P><P>Program&nbsp;<A HREF="page147.html#progqueuea"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the <tt>Queue</tt> class.The abstract <tt>Queue</tt> class extends the abstract <tt>Container</tt>class defined in Program&nbsp;<A HREF="page119.html#progcontainera"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.Hence, it comprises all the methods inherited from <tt>Container</tt>plus the methods,<tt>enqueue</tt> and <tt>eequeue</tt>,and the <tt>head</tt> property.As we did with stacks,we examine two queue implementations--an array-based one and a linked-list one.<P><P><A NAME="6320">&#160;</A><A NAME="progqueuea">&#160;</A> <IMG WIDTH=575 HEIGHT=374 ALIGN=BOTTOM ALT="program6246" SRC="img688.gif"  ><BR><STRONG>Program:</STRONG> Abstract <tt>Queue</tt> class.<BR><P><BR> <HR><UL> <LI> <A NAME="tex2html2902" HREF="page148.html#SECTION006210000000000000000">Array Implementation</A><LI> <A NAME="tex2html2903" HREF="page152.html#SECTION006220000000000000000">Linked-List Implementation</A><LI> <A NAME="tex2html2904" HREF="page156.html#SECTION006230000000000000000">Applications</A></UL><HR><A NAME="tex2html2899" HREF="page148.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2897" HREF="page130.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2891" HREF="page146.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2901" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright &#169; 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a>  All rights reserved.</ADDRESS></BODY></HTML>

⌨️ 快捷键说明

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