page538.html
来自「wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq」· HTML 代码 · 共 59 行
HTML
59 行
<HTML>
<HEAD>
<TITLE>Implementing Edges</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="tex2html8566" HREF="page539.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page539.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="tex2html8564" HREF="page536.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page536.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="tex2html8558" HREF="page537.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page537.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="tex2html8568" 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="tex2html8569" 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>
<H2><A NAME="SECTION0017220000000000000000">Implementing Edges</A></H2>
<P>
An edge in a directed graph is an ordered pair of vertices;
an edge in an undirected graph is a set of two vertices.
Because of the similarity of these concepts,
we use the same class for both--the context in which an edge is used determines whether it is directed
or undirected.
<P>
Program <A HREF="page538.html#proggraph2h" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page538.html#proggraph2h"><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 concrete class <tt>Edge</tt>.
Since we intend to insert instances of this class into containers,
the <tt>Edge</tt> class is derived from the <tt>Object</tt> base class.
<P>
<P><A NAME="50077"> </A><A NAME="proggraph2h"> </A> <IMG WIDTH=575 HEIGHT=238 ALIGN=BOTTOM ALT="program49704" SRC="img2374.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img2374.gif" ><BR>
<STRONG>Program:</STRONG> <tt>Edge</tt> Class Definition<BR>
<P>
<P>
The <tt>Edge</tt> class contains two member variables--<tt>v0</tt> and <tt>v1</tt>.
Each is a reference to a vertex.
When an instance of this class is used to represent a directed edge,
then the edge represented shall be <IMG WIDTH=57 HEIGHT=11 ALIGN=BOTTOM ALT="tex2html_wrap_inline71813" SRC="img2375.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img2375.gif" >.
I.e., <tt>v1</tt> is the head and <tt>v0</tt> is the tail.
Alternatively, when an <tt>Edge</tt> instance represents an undirected edge,
that edge is simply <IMG WIDTH=52 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline71815" SRC="img2376.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img2376.gif" >.
<P>
Program <A HREF="page538.html#proggraph2h" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page538.html#proggraph2h"><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 a constructor which takes two arguments,
both of them references to <tt>Vertex</tt> instances.
The effect of this constructor is to initialize the two
corresponding member variables accordingly.
<P>
In addition to the constructor,
there are three public member functions:
<tt>V0</tt>, <tt>V1</tt> and <tt>Mate</tt>.
All three of them are accessors.
The first are used to access the member variables <tt>v0</tt> and <tt>v1</tt>,
respectively.
<P>
For every instance <tt>e</tt> of the <tt>Edge</tt> class,
the <tt>Mate</tt> member function satisfies the following identities:
<P> <IMG WIDTH=190 HEIGHT=36 ALIGN=BOTTOM ALT="gather49739" SRC="img2377.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img2377.gif" ><P>
Therefore, if we know that a vertex <tt>v</tt> is one of the vertices of <tt>e</tt>,
then we can find the other vertex by calling <tt>e.Mate(v)</tt>.
<P>
<HR><A NAME="tex2html8566" HREF="page539.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page539.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="tex2html8564" HREF="page536.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page536.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="tex2html8558" HREF="page537.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page537.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="tex2html8568" 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="tex2html8569" 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 + -
显示快捷键?