?? page407.html
字號:
<HTML>
<HEAD>
<TITLE>Implementation</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="tex2html6957" HREF="page408.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page408.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="tex2html6955" HREF="page406.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page406.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="tex2html6949" HREF="page406.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page406.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="tex2html6959" 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="tex2html6960" 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="SECTION0013411000000000000000">Implementation</A></H3>
<P>
Program <A HREF="page407.html#progpartition2h" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page407.html#progpartition2h"><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> declares two classes--<tt>PartitionTree</tt> and <tt>PartitionAsForest</tt>.
The former is used to represent the individual elements or parts of a partition
and the latter encapsulates all of the parts that make up a given partition.
<P>
<P><A NAME="29324"> </A><A NAME="progpartition2h"> </A> <IMG WIDTH=575 HEIGHT=446 ALIGN=BOTTOM ALT="program29196" SRC="img1674.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1674.gif" ><BR>
<STRONG>Program:</STRONG> <tt>PartitionTree</tt> and <tt>PartitionAsForest</tt> Class Definitions<BR>
<P>
<P>
The <tt>PartitionTree</tt> class is derived
from the abstract base classes <tt>Set</tt> and <tt>Tree</tt>.
Since we are representing the parts of a partition using trees,
it makes sense that we derive them from the <tt>Tree</tt> class.
On the other hand, since a partition is a set of sets,
we must also derive the parts of a partition from the <tt>Set</tt> class.
In particular, this is necessary because of the
way that the <tt>Find</tt> and <tt>Join</tt> member functions are defined.
<P>
The <tt>PartitionTree</tt> class has three member variables--<tt>parent</tt>, <tt>item</tt> and <tt>rank</tt>.
Each instance of this class represents one node of a tree.
The <tt>parent</tt> member variable points to the parent of a given node
and the <tt>item</tt> member variable records the element of the universal set
that the given node represents.
The remaining variable, <tt>rank</tt>, is optional.
While it is not required in order to provide the basic functionality,
as shown below, the <tt>rank</tt> variable can be used in the implementation of
the <tt>Join</tt> operation to improve
the performance of subsequent <tt>Find</tt> operations.
<P>
The <tt>PartitionAsForest</tt> class represents a complete partition.
Since a partition is a set of sets, it is a container.
And since it supports a <em>find</em> operation,
the class <tt>PartitionAsForest</tt> is derived from
the abstract base class <tt>SearchableContainer</tt>.
The <tt>PartitionAsForest</tt> class contains
a single member variable, <tt>array</tt>,
which is an array of pointers to <tt>PartitionTree</tt> instances.
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" > element of the array always points to the tree node
that contains element <I>i</I> of the universe.
<P>
<HR><A NAME="tex2html6957" HREF="page408.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page408.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="tex2html6955" HREF="page406.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page406.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="tex2html6949" HREF="page406.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page406.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="tex2html6959" 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="tex2html6960" 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 © 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 + -