Category : C++ Source Code
Archive   : JCOOL01.ZIP
Filename : AVL_TREE.H
// Copyright (C) 1991 Texas Instruments Incorporated.
//
// Permission is granted to any individual or institution to use, copy, modify,
// and distribute this software, provided that this complete copyright and
// permission notice is maintained, intact, in all copies and supporting
// documentation.
//
// Texas Instruments Incorporated provides this software "as is" without
// express or implied warranty.
//
// Created: MBN 06/28/89 -- Initial design and implementation
// Updated: MBN 08/20/89 -- Updated template usage to reflect new syntax
// Updated: MBN 09/19/89 -- Added conditional exception handling
// Updated: DKM 11/05/89 -- Replaced re-balance after exceeding goal height
// with true AVL rotation alorythm.
// Updated: LGO 12/04/89 -- operator<< not inline
// Updated: LGO 12/04/89 -- balance not inline
// Updated: MJF 06/30/90 -- Added base class name to constructor initializer
// Updated: VDN 02/21/92 -- New lite version
// Updated: JAM 08/19/92 -- modernized template syntax, remove macro hacks
// Updated: JAM 08/19/92 -- made *_state typedef a nested typedef "IterState"
// as per new Iterator convention
//
// The AVL_Tree
// The AVL_Tree
// class and both are parameterized over some type Type. An AVL tree is a
// compromise between the expense of a fully balanced binary tree and the
// desire for efficient search times for both average and worst case scenarios.
// As a result, an AVL tree maintains a binary tree that is height-balanced,
// insuring that the minimum and maximum depth of any path through the binary
// tree is within some specified range.
//
// The AVL_Tree
// constructors. The first constructor takes an optional argument that allows
// the user to specify the height-balance limit (the default is two). A
// height-balance value of zero indicates that the tree should remain
// completely balanced. The second constructor takes a reference to another
// AVL_Tree
//
// The AVL_Tree
// Binary_Tree
// affect the structure of the tree, thus potentially requiring one or more
// subtrees to be shaken and restructured.
//
#ifndef AVL_TREEH // If no definition for class
#define AVL_TREEH
#ifndef BINARY_TREEH // If no definition for class
#include
#endif
template
class CoolAVL_Tree : public CoolBinary_Tree
public:
typedef CoolBT_State IterState;
/*inline##*/ CoolAVL_Tree() {}; // Simple constructor
CoolAVL_Tree(const CoolAVL_Tree
CoolAVL_Tree(const CoolBinary_Tree
~CoolAVL_Tree(); // Destructor
inline Boolean put (const Type&); // Add an item to tree
inline Boolean remove (const Type&); // Remove item from tree
inline Boolean remove (); // Remove item current position
void balance (); // Special balance for AVL
inline CoolAVL_Tree
inline CoolAVL_Tree
friend ostream& operator<< (ostream&, const CoolAVL_Tree
/*inline##*/ friend ostream& operator<< (ostream&, const CoolAVL_Tree
};
// put -- Add a value to the AVL tree if it is not already there and balance
// tree if necessary
// Input: Reference to value to add to tree
// Output: TRUE if item added, FALSE otherwise
template
inline Boolean CoolAVL_Tree
return (CoolBinary_Tree
}
// remove -- Remove a value from the AVL tree. Deletion of a node and balance
// tree if necessary
// Input: Reference to value to remove
// Output: TRUE if item removed, FALSE otherwise
template
inline Boolean CoolAVL_Tree
return (CoolBinary_Tree
}
// remove -- Remove node at current position in the tree and balance tree
// Input: None
// Output: Value of node removed from tree
template
inline Boolean CoolAVL_Tree
return (CoolBinary_Tree
}
template
inline CoolAVL_Tree
CoolBinary_Tree
return *this; // Return tree reference
}
template
inline CoolAVL_Tree
CoolBinary_Tree
this->balance(); // Do an AVL balance
return *this; // Return tree reference
}
template
inline ostream& operator<< (ostream& os, const CoolAVL_Tree
return operator<< (os, *av);
}
#endif // End AVL_TREEH #if
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/