⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avl.shtml.htm

📁 mfc资料集合5
💻 HTM
字号:
<HTML>
<!-- Header information-->
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Guy Gascoigne - Piggford">
   <TITLE>C++ - AVLTree - template version </TITLE>
</HEAD>

<!-- Set background properties -->
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed">

<!-- A word from our sponsors... -->
<table WIDTH="100%">
<tr WIDTH="100%"><td><td></tr>
</table>


<!-- Article Title -->
<CENTER><H3><FONT COLOR="#AOAO99">
AVLTree - template version

</FONT></H3></CENTER>
<CENTER><H3><HR></H3></CENTER>

<!-- Author and contact details -->
This article was contributed by <A HREF="mailto:Jaeger-Geitersdorf@t-online.de">Andreas J鋑er</A>.

<!-- The article... -->
<p>
I have implemented the binary tree's of Addison-Velski and Landis
(AVL-Tree's), which allow Standard-operation like Insert, Search and delete
in logarithmical time. Ordinary binary trees can become very obscure, they
can become a linear structure and the basic operations take linear and not
logarithmical time. The advantage of the AVL-Tree's is a strategy of
restructurate the tree after Insert- and Delete-operations. The
restructuration itself only takes logarithmical time. So the trees are
high-efficient binary trees to hold a large number of items. I use such
trees to sort data. The sort of data using AVL-Trees takes n*log(n)-time,
so you can sort a lot of data in optimal time. I have sorted with that
technology hundrets of thousands of items, within a quarter of an hour. It
is very easy to eliminate duplicates, duplicates will  not be inserted in
the tree. What other algorithm works so efficient??? And the greatest
advantage is, that the code is absolutely easy to use, 10 lines are enough
to sort a file. The Trees are implemented as templates, so you can use
everything you want as item. Items only must be comparable. The code is
self-documentating. The classes are CAVLNode&lt;class T&gt;, CAVLTree&lt;class T&gt;
and CAVLTreeIterator&lt;class T&gt;.
<p>
Here is an example to sort a file:

<pre><tt><font COLOR="#990000">
// sample code
#include "AVLBaum.h"

void SortFile(const char* iname, const char* ofname)
{
	ifstream is(ifname);
	ofstream os(ofname);
	char buffer[255];
	CAVLTree&lt;CString&gt; tree;
	while (is.getline(buffer, sizeof(buffer)-1)
		tree.Insert(new CString(buffer));
	CAVLTreeIterator&lt;CString&gt; iter(tree);
	while (iter)
	{
		os &lt;&lt; *(iter.GetData()) &lt;&lt; endl;
		iter++;
	}
}

// end of sample code
</font></tt></pre>
And now the "AVLBaum.h":
<pre><tt><font COLOR="#990000">
// Creator: Andreas J鋑er
//          Ortsstr. Nr. 2
//        D-07407 Geitersdorf
//
// Last updated: 04. April 1998
// e-mail: Jaeger-Geitersdorf@t-online.de
//
// you can use and modify that code free when preserving
// the name of the creator
//
// have fun!
//
////////////////////////////////////////////////////////////////
// Note:                                                      //
// there must be a function T::Compare(T&amp;)                    //
// or the function Compare of teh Template-Klasse             //
// CAVLNode&lt;T&gt; has to be overridden.                          //
////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////
// Vorbemerkungen:                                            //
// Es mu

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -