page161.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 47 行
HTML
47 行
<HTML><HEAD><TITLE>dequeueTail and getTail Methods</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="tex2html3058" HREF="page162.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3056" HREF="page159.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3052" HREF="page160.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html3060" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION006312000000000000000"><tt>dequeueTail</tt> and <tt>getTail</tt> Methods</A></H3><P>Program <A HREF="page161.html#progdequeAsArrayb"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the<tt>dequeueTail</tt> and <tt>getTail</tt> methodsof the <tt>DequeAsArray</tt> class.<P><P><A NAME="7923"> </A><A NAME="progdequeAsArrayb"> </A> <IMG WIDTH=575 HEIGHT=390 ALIGN=BOTTOM ALT="program7801" SRC="img704.gif" ><BR><STRONG>Program:</STRONG> <tt>DequeAsArray</tt> class <tt>dequeueTail</tt> and <tt>getTail</tt> methods.<BR><P><P>The <tt>getTail</tt> methodthat returns the object found at the tail of the deque,having first checked to see that the deque is not empty.If the deque is empty, it raises a <tt>ContainerEmpty</tt> exception.Under normal circumstances, we expect that the deque will not be empty.Therefore, the normal running time of this method is <I>O</I>(1).<P>The <tt>DequeueTail</tt> method removes an object from the tailof the deque and returns that object.First, it checks that the deque is not emptyand throws an exception when it is.If the deque is not empty,the method sets aside the object at the tailin the local variable <tt>result</tt>;it decreases the <tt>_tail</tt> instance attribute by one modulo the length of the array;adjusts the <tt>_count</tt> accordingly;and returns <tt>result</tt>.All this can be done in a constant amount of timeso the running time of <tt>DequeueTail</tt> is a constant.<P><HR><A NAME="tex2html3058" HREF="page162.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3056" HREF="page159.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3052" HREF="page160.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html3060" 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 © 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 + -
显示快捷键?