?? binarysearchtree.html
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Fri Aug 23 13:18:11 EDT 2002 --><TITLE>: Class BinarySearchTree</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><a href=../copyright.html target=_top>© 1998-2002 McGraw-Hill</a></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../structure/Association.html"><B>PREV CLASS</B></A> <A HREF="../structure/BinaryTree.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="BinarySearchTree.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">structure</FONT><BR>Class BinarySearchTree</H2><PRE><A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">java.lang.Object</A> | +--<A HREF="../structure/AbstractStructure.html">structure.AbstractStructure</A> | +--<B>structure.BinarySearchTree</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="../structure/OrderedStructure.html">OrderedStructure</A>, <A HREF="../structure/Structure.html">Structure</A></DD></DL><DL><DT><B>Direct Known Subclasses:</B> <DD><A HREF="../structure/SplayTree.html">SplayTree</A></DD></DL><HR><DL><DT>public class <B>BinarySearchTree</B><DT>extends <A HREF="../structure/AbstractStructure.html">AbstractStructure</A><DT>implements <A HREF="../structure/OrderedStructure.html">OrderedStructure</A></DL><P>A binary search tree structure. This structure maintains data in an ordered tree. It does not keep the tree balanced, so performance may degrade if the tree height is not optimal. <P> Example usage: <P> To create a Binary search tree containing the months of the year and to print out this tree as it grows we could use the following. <P> <pre> public static void main(String[] argv){ BinarySearchTree test = new <A HREF="../structure/BinarySearchTree.html#BinarySearchTree()"><CODE>BinarySearchTree()</CODE></A>; //declare an array of months String[] months = new String[]{"March", "May", "November", "August", "April", "January", "December", "July", "February", "June", "October", "September"}; //add the months to the tree and print out the tree as it grows for(int i=0; i < months.length; i++){ test.<A HREF="../structure/BinarySearchTree.html#add(java.lang.Object)"><CODE>add(months[i])</CODE></A>; System.out.println("Adding: " + months[i] + "\n" +test.<A HREF="../structure/BinarySearchTree.html#treeString()"><CODE>treeString()</CODE></A>); } } </pre><P><DL><DT><B>See Also: </B><DD><A HREF="../structure/SplayTree.html"><CODE>SplayTree</CODE></A>, <A HREF="../structure/BinaryTree.html"><CODE>BinaryTree</CODE></A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><A NAME="field_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Field Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected int</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#count">count</A></B></CODE><BR> The number of nodes in the tree</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/util/Comparator.html">Comparator</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#ordering">ordering</A></B></CODE><BR> The ordering used on this search tree.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="../structure/BinaryTree.html">BinaryTree</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#root">root</A></B></CODE><BR> A reference to the root of the tree</TD></TR></TABLE> <!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#BinarySearchTree()">BinarySearchTree</A></B>()</CODE><BR> Constructs a binary search tree with no data</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#BinarySearchTree(java.util.Comparator)">BinarySearchTree</A></B>(<A HREF="http://java.sun.com/j2se/1.3/docs/api/java/util/Comparator.html">Comparator</A> alternateOrder)</CODE><BR> Constructs a binary search tree with no data</TD></TR></TABLE> <!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#add(java.lang.Object)">add</A></B>(<A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A> value)</CODE><BR> Add a (possibly duplicate) value to binary search tree</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#clear()">clear</A></B>()</CODE><BR> Removes all data from the binary search tree</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#contains(java.lang.Object)">contains</A></B>(<A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A> value)</CODE><BR> Determines if the binary search tree contains a value</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#get(java.lang.Object)">get</A></B>(<A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A> value)</CODE><BR> Returns reference to value found within three.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#hashCode()">hashCode</A></B>()</CODE><BR> Returns the hashCode of the value stored by this object.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#isEmpty()">isEmpty</A></B>()</CODE><BR> Checks for an empty binary search tree</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/util/Iterator.html">Iterator</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#iterator()">iterator</A></B>()</CODE><BR> Returns an iterator over the binary search tree.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="../structure/BinaryTree.html">BinaryTree</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#locate(structure.BinaryTree, java.lang.Object)">locate</A></B>(<A HREF="../structure/BinaryTree.html">BinaryTree</A> root, <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A> value)</CODE><BR> </TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="../structure/BinaryTree.html">BinaryTree</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#predecessor(structure.BinaryTree)">predecessor</A></B>(<A HREF="../structure/BinaryTree.html">BinaryTree</A> root)</CODE><BR> </TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#remove(java.lang.Object)">remove</A></B>(<A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A> value)</CODE><BR> Remove an value "equals to" the indicated value.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="../structure/BinaryTree.html">BinaryTree</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#removeTop(structure.BinaryTree)">removeTop</A></B>(<A HREF="../structure/BinaryTree.html">BinaryTree</A> topNode)</CODE><BR> Removes the top node of the tree rooted, performs the necissary rotations to reconnect the tree.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#size()">size</A></B>()</CODE><BR> Determines the number of data values within the tree</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="../structure/BinaryTree.html">BinaryTree</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#successor(structure.BinaryTree)">successor</A></B>(<A HREF="../structure/BinaryTree.html">BinaryTree</A> root)</CODE><BR> </TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html">String</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#toString()">toString</A></B>()</CODE><BR> Returns a string representing tree</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html">String</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/BinarySearchTree.html#treeString()">treeString</A></B>()</CODE><BR> Returns a (possibly long) string representing tree.</TD></TR></TABLE> <A NAME="methods_inherited_from_class_structure.AbstractStructure"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class structure.<A HREF="../structure/AbstractStructure.html">AbstractStructure</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../structure/AbstractStructure.html#elements()">elements</A>, <A HREF="../structure/AbstractStructure.html#values()">values</A></CODE></TD></TR></TABLE> <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class java.lang.<A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#<clinit>()"><clinit></A>, <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#clone()">clone</A>, <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#equals(java.lang.Object)">equals</A>, <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#finalize()">finalize</A>, <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#getClass()">getClass</A>, <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#notify()">notify</A>, <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#notifyAll()">notifyAll</A>, <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#registerNatives()">registerNatives</A>, <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#wait()">wait</A>, <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#wait(long)">wait</A>, <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#wait(long, int)">wait</A></CODE></TD></TR></TABLE> <A NAME="methods_inherited_from_class_structure.Structure"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from interface structure.<A HREF="../structure/Structure.html">Structure</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../structure/Structure.html#elements()">elements</A>, <A HREF="../structure/Structure.html#values()">values</A></CODE></TD></TR></TABLE> <P><!-- ============ FIELD DETAIL =========== --><A NAME="field_detail"><!-- --></A>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -