?? page390.html
字號:
<HTML>
<HEAD>
<TITLE>Array and Bit-Vector Sets</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="tex2html6747" HREF="page391.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page391.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="tex2html6745" HREF="page387.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page387.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="tex2html6739" HREF="page389.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page389.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="tex2html6749" 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="tex2html6750" 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>
<H1><A NAME="SECTION0013200000000000000000">Array and Bit-Vector Sets</A></H1>
<P>
In this section we consider finite sets over a finite universe.
Specifically, the universe we consider is <IMG WIDTH=115 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline67264" SRC="img1601.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1601.gif" >,
the set of integers in the range from zero to <I>N</I>-1,
for some fixed and relatively small value of <I>N</I>.
<P>
Let <IMG WIDTH=150 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline67278" SRC="img1605.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1605.gif" > be the universe.
Every set which we wish to represent is a subset of <I>U</I>.
The set of all subsets of <I>U</I> is called the <em>power set</em><A NAME=28226> </A>
of <I>U</I> and is written <IMG WIDTH=16 HEIGHT=13 ALIGN=BOTTOM ALT="tex2html_wrap_inline67286" SRC="img1606.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1606.gif" >.
Thus, the sets which we wish to represent are the <em>elements</em> of <IMG WIDTH=16 HEIGHT=13 ALIGN=BOTTOM ALT="tex2html_wrap_inline67286" SRC="img1606.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1606.gif" >.
The number of elements in the set <I>U</I>, written |<I>U</I>|, is <I>N</I>.
Similarly, <IMG WIDTH=114 HEIGHT=29 ALIGN=MIDDLE ALT="tex2html_wrap_inline67296" SRC="img1607.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1607.gif" >.
This observation should be obvious:
For each element of the universal set <I>U</I> there are only two possibilities:
Either it is, or it is not,
a member of the given set.
<P>
This suggests a relatively straightforward
representation of the elements of <IMG WIDTH=16 HEIGHT=13 ALIGN=BOTTOM ALT="tex2html_wrap_inline67286" SRC="img1606.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1606.gif" >--an array of Boolean values, one for each element of the universal set.
By using array subscripts in <I>U</I>,
we can represent the set implicitly.
I.e., <I>i</I> is a member of the set if 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" > array element is true.
<P>
Program <A HREF="page390.html#progbitset1h" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page390.html#progbitset1h"><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 the class <tt>SetAsArray</tt>.
This class uses an array of length <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" >
to represent the elements of <IMG WIDTH=16 HEIGHT=13 ALIGN=BOTTOM ALT="tex2html_wrap_inline67286" SRC="img1606.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1606.gif" > where <IMG WIDTH=150 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline67278" SRC="img1605.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1605.gif" >.
A <tt>SetAsArray</tt> is a <tt>Set</tt>.
Therefore, it supports the basic operations of searchable containers
including <tt>Insert</tt>, <tt>IsMember</tt>, and <tt>Withdraw</tt>.
<P>
<P><A NAME="28725"> </A><A NAME="progbitset1h"> </A> <IMG WIDTH=575 HEIGHT=333 ALIGN=BOTTOM ALT="program28238" SRC="img1609.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1609.gif" ><BR>
<STRONG>Program:</STRONG> <tt>SetAsArray</tt> Class Definition<BR>
<P>
<P>
In addition, Program <A HREF="page390.html#progbitset1h" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page390.html#progbitset1h"><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 operators
<tt>+</tt>, <tt>*</tt>, <tt>-</tt>, <tt>==</tt>, and <tt><=</tt>.
The first three operators correspond to
set union, set intersection, and set difference (respectively).
The last two are used to compare two sets and
to determine whether one set is a subset of another.
<P>
<BR> <HR>
<UL>
<LI> <A NAME="tex2html6751" HREF="page391.html#SECTION0013201000000000000000" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page391.html#SECTION0013201000000000000000">Basic Operations</A>
<LI> <A NAME="tex2html6752" HREF="page392.html#SECTION0013202000000000000000" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page392.html#SECTION0013202000000000000000">Union, Intersection and Difference</A>
<LI> <A NAME="tex2html6753" HREF="page393.html#SECTION0013203000000000000000" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page393.html#SECTION0013203000000000000000">Comparing Sets</A>
<LI> <A NAME="tex2html6754" HREF="page394.html#SECTION0013210000000000000000" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page394.html#SECTION0013210000000000000000">Bit-Vector Sets</A>
</UL>
<HR><A NAME="tex2html6747" HREF="page391.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page391.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="tex2html6745" HREF="page387.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page387.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="tex2html6739" HREF="page389.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page389.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="tex2html6749" 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="tex2html6750" 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 + -