page136.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 41 行
HTML
41 行
<HTML><HEAD><TITLE>accept Method</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="tex2html2779" HREF="page137.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2777" HREF="page132.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2771" HREF="page135.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html2781" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION006114000000000000000"><tt>accept</tt> Method</A></H3><P>Program <A HREF="page136.html#progstackAsArrayc"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the <tt>accept</tt>method for the <tt>StackAsArray</tt> class.As discussed in Chapter <A HREF="page111.html#chapadts"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,the purpose of the <tt>accept</tt> method of a container is to accept a visitorand to cause it to visit one-by-one all of the contained objects.<P><P><A NAME="5645"> </A><A NAME="progstackAsArrayc"> </A> <IMG WIDTH=575 HEIGHT=199 ALIGN=BOTTOM ALT="program5332" SRC="img665.gif" ><BR><STRONG>Program:</STRONG> <tt>StackAsArray</tt> class <tt>accept</tt> method.<BR><P><P>The body of the <tt>accept</tt> method is simply a loopwhich calls the <tt>visit</tt> method for each object in the stack.The running time of the <tt>accept</tt> method depends onthe running time of the <tt>visit</tt> method.Let <IMG WIDTH=53 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline60701" SRC="img666.gif" > be the running time of the <tt>visit</tt> method.In addition to the time for the method call,each iteration of the loop incurs a constant overhead.Consequently,the total running time for <tt>accept</tt> is <IMG WIDTH=117 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline60703" SRC="img667.gif" >,where <I>n</I> is the number of objects in the container.And if <IMG WIDTH=108 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline60707" SRC="img668.gif" >, the total running time is to <I>O</I>(<I>n</I>).<P><HR><A NAME="tex2html2779" HREF="page137.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2777" HREF="page132.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2771" HREF="page135.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html2781" 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 + -
显示快捷键?