page392.html
来自「wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq」· HTML 代码 · 共 60 行
HTML
60 行
<HTML>
<HEAD>
<TITLE>Union, Intersection and Difference</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="tex2html6775" HREF="page393.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page393.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="tex2html6773" HREF="page390.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page390.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="tex2html6767" HREF="page391.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page391.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="tex2html6777" 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="tex2html6778" 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="SECTION0013202000000000000000">Union, Intersection and Difference</A></H3>
<P>
Program <A HREF="page392.html#progbitset2c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page392.html#progbitset2c"><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> overloads the three operators,
<tt>operator+</tt>, <tt>operator*</tt> and <tt>operator-</tt>,
to provide the union, intersection, and difference operations
for <tt>SetAsArray</tt> instances.
Operators <tt>+</tt>, <tt>*</tt> and <tt>-</tt>
correspond to <IMG WIDTH=9 HEIGHT=11 ALIGN=BOTTOM ALT="tex2html_wrap_inline67324" SRC="img1611.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1611.gif" >, <IMG WIDTH=9 HEIGHT=11 ALIGN=BOTTOM ALT="tex2html_wrap_inline67326" SRC="img1612.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1612.gif" > and -, respectively.
<P>
<P><A NAME="28738"> </A><A NAME="progbitset2c"> </A> <IMG WIDTH=575 HEIGHT=563 ALIGN=BOTTOM ALT="program28308" SRC="img1613.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1613.gif" ><BR>
<STRONG>Program:</STRONG> <tt>SetAsArray</tt> Class Union, Intersection and Difference Operator Definitions<BR>
<P>
<P>
The set union operator takes two references to <tt>SetAsArray</tt> instances,
<tt>s</tt> and <tt>t</tt>,
and computes a result of type <tt>SetAsArray</tt>.
The implementation given requires
that the <tt>s</tt> and <tt>t</tt> sets be compatible.
Two sets are deemed to be compatible if they have the same universe.
The result also has the same universe.
Consequently, the Boolean array in all three sets has the same length, <I>N</I>.
The set union routine creates a result array of the required size
and then computes the elements of the array as required.
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 result is <tt>true</tt>
if either 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 <tt>s</tt>
or 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 <tt>t</tt> is <tt>true</tt>.
Thus, set union is implemented using
the Boolean <em>or</em><A NAME=28331> </A><A NAME=28332> </A> operator,
<tt>||</tt>.
<P>
The set intersection operator is almost identical to set union,
except that the elements of the result are computed using
the Boolean <em>and</em><A NAME=28335> </A><A NAME=28336> </A> operator.
The set difference operator is also very similar.
In this case, an item is an element of the result
only if it is a member of <tt>s</tt> and not a member of <tt>t</tt>.
<P>
Because all three routines are almost identical,
their running times are essentially the same.
I.e., the running time of
the set union, intersection, and difference operations is <I>O</I>(<I>N</I>),
where <IMG WIDTH=144 HEIGHT=11 ALIGN=BOTTOM ALT="tex2html_wrap_inline67308" SRC="img1608.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1608.gif" >.
<P>
<HR><A NAME="tex2html6775" HREF="page393.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page393.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="tex2html6773" HREF="page390.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page390.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="tex2html6767" HREF="page391.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page391.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="tex2html6777" 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="tex2html6778" 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 + =
减小字号Ctrl + -
显示快捷键?