page164.html

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

HTML
48
字号
<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="tex2html3091" HREF="page165.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3089" HREF="page162.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3085" HREF="page163.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html3093" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION006322000000000000000"><tt>dequeueTail</tt> and <tt>getTail</tt> Methods</A></H3><P>Program&nbsp;<A HREF="page164.html#progdequeAsLinkedListb"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> definesand <tt>DequeueTail</tt> and <tt>getTail</tt> methodsof the <tt>DequeAsArray</tt> class.<P><P><A NAME="7931">&#160;</A><A NAME="progdequeAsLinkedListb">&#160;</A> <IMG WIDTH=575 HEIGHT=313 ALIGN=BOTTOM ALT="program7849" SRC="img706.gif"  ><BR><STRONG>Program:</STRONG> <tt>DequeAsLinkedList</tt> class <tt>dequeueTail</tt> 	and <tt>getTail</tt> methods.<BR><P><P>The <tt>getTail</tt> methodreturns the object at the tail of the deque.The tail of the deque is in the last element of the linked list.In Chapter&nbsp;<A HREF="page81.html#chapfds"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> we saw that the running time of<tt>LinkedList.last</tt> property is a constant,Therefore, the normal running time for this accesor 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 verifies that the deque is not emptyand throws an exception when it is.If the deque is not empty,<tt>dequeueTail</tt> saves the last item in the linked listin the local variable <tt>result</tt>.Then that item is extracted from the linked list.When using the <tt>LinkedList</tt> class from Chapter&nbsp;<A HREF="page81.html#chapfds"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,the time required to extract the last item from a list is <I>O</I>(<I>n</I>),where  <IMG WIDTH=72 HEIGHT=9 ALIGN=BOTTOM ALT="tex2html_wrap_inline60691" SRC="img663.gif"  > is the number of items in the list.As a result,the running time of <tt>DequeueTail</tt> is <I>O</I>(<I>n</I>).<P><HR><A NAME="tex2html3091" HREF="page165.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3089" HREF="page162.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3085" HREF="page163.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html3093" 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 + -
显示快捷键?