⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page134.html

📁 wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq
💻 HTML
字号:
<HTML>
<HEAD>
<TITLE>Constructor and Destructor</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
 <img src="cover75.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cover75.gif" alt="Logo" align=right>
<b>Data Structures and Algorithms 
with Object-Oriented Design Patterns in C++</b><br>
<A NAME="tex2html3569" HREF="page135.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page135.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html3567" HREF="page132.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page132.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html3561" HREF="page133.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page133.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html3571" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html3572" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <BR><HR>
<H3><A NAME="SECTION007112000000000000000">Constructor and Destructor</A></H3>
<P>
The definitions of the <tt>StackAsArray</tt> class constructor
and destructor are given in Program&nbsp;<A HREF="page134.html#progstack1c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page134.html#progstack1c"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>.
The constructor takes a single parameter, <tt>size</tt>,
which specifies the maximum number of items that can be stored in the stack.
The variable <tt>array</tt> is initialized to be an array of length <tt>size</tt>.
Its constructor requires <I>O</I>(1) time to construct an array of pointers.
Therefore, the total running time for the <tt>StackAsArray</tt>
constructor is <I>O</I>(1).
<P>
<P><A NAME="6277">&#160;</A><A NAME="progstack1c">&#160;</A> <IMG WIDTH=575 HEIGHT=317 ALIGN=BOTTOM ALT="program5841" SRC="img708.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img708.gif"  ><BR>
<STRONG>Program:</STRONG> <tt>StackAsArray</tt> Class Constructor, 	Destructor and <tt>Purge</tt> Member Function Definitions<BR>
<P>
<P>
The <tt>StackAsArray</tt> destructor
simply calls the <tt>Purge</tt> member function.
The behavior of the <tt>Purge</tt> function
depends on whether the stack (as a container) is the owner
of the contained objects.
If it is the owner,
then the contained objects must be deleted by the <tt>Purge</tt> function.
In this case, the <tt>Purge</tt> function deletes one-by-one
the first <tt>count</tt> elements of the array.
In general, because of the polymorphic implementation of <tt>Object</tt>s,
we cannot know the running time to delete the array elements.
However, if we assume that the destructors for all the objects
each run in constant time,
the total running time for the <tt>Purge</tt> function is <I>O</I>(<I>n</I>),
where  <IMG WIDTH=72 HEIGHT=9 ALIGN=BOTTOM ALT="tex2html_wrap_inline61308" SRC="img709.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img709.gif"  >,
i.e., <I>n</I> is the number of elements in the stack.
<P>
<HR><A NAME="tex2html3569" HREF="page135.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page135.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html3567" HREF="page132.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page132.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html3561" HREF="page133.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page133.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html3571" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html3572" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <P><ADDRESS>
<img src="bruno.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/bruno.gif" alt="Bruno" align=right>
<a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html">Copyright &#169; 1997</a> by <a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html">Bruno R. Preiss, P.Eng.</a>  All rights reserved.

</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

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