📄 page142.html
字号:
<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="tex2html2848" HREF="page143.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2846" HREF="page138.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2840" HREF="page141.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html2850" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION006124000000000000000"><tt>accept</tt> Method</A></H3><P>The <tt>accept</tt> method of the <tt>StackAsLinkedList</tt> classis defined in Program <A HREF="page142.html#progstackAsLinkedListc"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.The <tt>accept</tt> method takes a visitorand calls its <tt>visit</tt> methodone-by-one for all of the objects on the stack.<P><P><A NAME="5664"> </A><A NAME="progstackAsLinkedListc"> </A> <IMG WIDTH=575 HEIGHT=237 ALIGN=BOTTOM ALT="program5490" SRC="img672.gif" ><BR><STRONG>Program:</STRONG> <tt>StackAsLinkedList</tt> class <tt>accept</tt> method.<BR><P><P>The implementation of the <tt>accept</tt> methodfor the <tt>StackAsLinkedList</tt> class mirrors that ofthe <tt>StackAsArray</tt> class shown in Program <A HREF="page136.html#progstackAsArrayc"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.In this case, the linked list is traversed from front to back,i.e., from the top of the stack to the bottom.As each element of the linked list is encountered,the <tt>visit</tt> method is called.If <IMG WIDTH=53 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline60701" SRC="img666.gif" > is the running time of the <tt>visit</tt> method,the total running time for <tt>accept</tt> is <IMG WIDTH=117 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline60703" SRC="img667.gif" >,where <IMG WIDTH=72 HEIGHT=9 ALIGN=BOTTOM ALT="tex2html_wrap_inline60691" SRC="img663.gif" > is the number of objects in the container.If we assume that <IMG WIDTH=108 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline60707" SRC="img668.gif" >,the total running time is <I>O</I>(<I>n</I>).<P><HR><A NAME="tex2html2848" HREF="page143.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2846" HREF="page138.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2840" HREF="page141.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html2850" 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -