page225.html

来自「wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq」· HTML 代码 · 共 59 行

HTML
59
字号
<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="tex2html4699" HREF="page226.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page226.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="tex2html4697" HREF="page223.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page223.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="tex2html4691" HREF="page224.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page224.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="tex2html4701" 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="tex2html4702" 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="SECTION009412000000000000000">Constructor and Destructor</A></H3>
<P>
The constructor and destructor for the <tt>ChainedHashTable</tt>
class are defined in Program&nbsp;<A HREF="page225.html#proghashtbl2c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page225.html#proghashtbl2c"><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 argument of type <tt>unsigned int</tt>
which specifies the size of hash table desired.
The constructor simply initializes the <tt>HashTable</tt> base class
and the <tt>array</tt> member variable accordingly.
Initializing the <tt>array</tt> variable involves constructing
the required number of empty linked lists.
Consequently, the running time for the <tt>ChainedHashTable</tt>
constructor is <I>O</I>(<I>M</I>) where <I>M</I> is the size of the hash table.
<P>
<P><A NAME="12071">&#160;</A><A NAME="proghashtbl2c">&#160;</A> <IMG WIDTH=575 HEIGHT=469 ALIGN=BOTTOM ALT="program11924" SRC="img971.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img971.gif"  ><BR>
<STRONG>Program:</STRONG> <tt>ChainedHashTable</tt> Class Constructor, Destructor 	and <tt>Purge</tt> Member Function Definitions<BR>
<P>
<P>
The <tt>ChainedHashTable</tt> destructor
simply calls the <tt>Purge</tt> member function.
Since the <tt>ChainedHashTable</tt> is a container,
the <tt>Purge</tt> function must delete any contained objects
if it is the owner of those objects.
Therefore, the <tt>Purge</tt> function is required to traverse
each of the linked lists in the array.
<P>
To determine the running time of the <tt>Purge</tt> function,
we will assume that there are <I>n</I> contained objects
and the length of the array is <I>M</I>.
Furthermore, let  <IMG WIDTH=13 HEIGHT=15 ALIGN=MIDDLE ALT="tex2html_wrap_inline62818" SRC="img972.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img972.gif"  > be the number of items
in the  <IMG WIDTH=17 HEIGHT=13 ALIGN=BOTTOM ALT="tex2html_wrap_inline58387" SRC="img77.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img77.gif"  > linked list
for  <IMG WIDTH=132 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline62822" SRC="img973.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img973.gif"  >.
Note that  <IMG WIDTH=94 HEIGHT=33 ALIGN=MIDDLE ALT="tex2html_wrap_inline62824" SRC="img974.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img974.gif"  >.
The running time of the inner loop
for the  <IMG WIDTH=17 HEIGHT=13 ALIGN=BOTTOM ALT="tex2html_wrap_inline58387" SRC="img77.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img77.gif"  > iteration of the outer loop
is  <IMG WIDTH=193 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline62828" SRC="img975.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img975.gif"  >.
The constant overhead arises from the loop termination test
which must be done at least once.
The total running time of the destructor is given by
<P> <IMG WIDTH=475 HEIGHT=47 ALIGN=BOTTOM ALT="displaymath62808" SRC="img976.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img976.gif"  ><P>
If we assume that  <IMG WIDTH=120 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline62830" SRC="img977.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img977.gif"  >,
the running time simplifies to <I>O</I>(<I>M</I>+<I>n</I>).
<P>
<HR><A NAME="tex2html4699" HREF="page226.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page226.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="tex2html4697" HREF="page223.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page223.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="tex2html4691" HREF="page224.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page224.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="tex2html4701" 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="tex2html4702" 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 + =
减小字号Ctrl + -
显示快捷键?