page288.html
来自「wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq」· HTML 代码 · 共 54 行
HTML
54 行
<HTML>
<HEAD>
<TITLE>Subtree, AttachSubtree and DetachSubtree
Member Functions</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="tex2html5487" HREF="page289.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page289.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="tex2html5485" HREF="page282.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page282.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="tex2html5481" HREF="page287.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page287.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="tex2html5489" 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="tex2html5490" 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="SECTION0010646000000000000000"><tt>Subtree</tt>, <tt>AttachSubtree</tt> and <tt>DetachSubtree</tt>
Member Functions</A></H3>
<P>
Program <A HREF="page288.html#prognarytree3c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page288.html#prognarytree3c"><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> defines the three member functions
for manipulating the subtrees of an <I>N</I>-ary tree.
The <tt>Subtree</tt> member function takes as its lone argument
an <tt>unsigned int</tt>, <tt>i</tt>, which must be between 0 and <I>N</I>-1.
It returns a reference to the <IMG WIDTH=20 HEIGHT=13 ALIGN=BOTTOM ALT="tex2html_wrap_inline63948" SRC="img1175.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1175.gif" > subtree of the given tree.
Note that this operation is only defined for a non-empty <I>N</I>-ary tree.
Given that the tree is not empty,
the running time is <I>O</I>(1).
<P>
<P><A NAME="17035"> </A><A NAME="prognarytree3c"> </A> <IMG WIDTH=575 HEIGHT=486 ALIGN=BOTTOM ALT="program16977" SRC="img1182.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1182.gif" ><BR>
<STRONG>Program:</STRONG> <tt>NaryTree</tt> Class Member Function Definitions<BR>
<P>
<P>
The <tt>AttachSubtree</tt> member function takes two arguments.
The first is an unsigned integer <tt>i</tt> between 0 and <I>N</I>-1.
The second is a reference to a <tt>NaryTree</tt> instance.
The purpose of this routine is to make the <I>N</I>-ary tree specified
by the second argument become 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" > subtree of the given tree.
It is only possible to attach a subtree to a non-empty node and
it is only possible to attach a subtree
in a place of occupied by an empty subtree.
If none of the exceptions are thrown,
the running time of this function is simply <I>O</I>(1).
<P>
The <tt>DetachSubtree</tt> member function takes a single argument <tt>i</tt>
which is an unsigned integer between 0 and <I>N</I>-1.
This routine removes the <IMG WIDTH=20 HEIGHT=13 ALIGN=BOTTOM ALT="tex2html_wrap_inline63948" SRC="img1175.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1175.gif" > subtree from a given <I>N</I>-ary
tree and returns a reference to that subtree.
Of course, it is only possible to remove a subtree from a non-empty tree.
Since every non-empty node must have <I>N</I> subtrees,
when a subtree is removed it is replaced by an empty tree.
Clearly, the running time is <I>O</I>(1) if we assume that no exceptions are thrown.
<P>
<HR><A NAME="tex2html5487" HREF="page289.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page289.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="tex2html5485" HREF="page282.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page282.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="tex2html5481" HREF="page287.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page287.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="tex2html5489" 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="tex2html5490" 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 + -
显示快捷键?