Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/DataType/BST/BinNode.cpp

Go to the documentation of this file.
00001 // BinNode.cpp - Binary Search Tree Node Class Implementation
00002 #include <j2k/DataType/BST/BinNode.hpp>
00003 
00004 // This creates space for the freelist variable
00005 BinNode* BinNode::freelist = NULL;
00006 
00007 // Two constructors -- with and without initial values
00008 inline BinNode::BinNode() 
00009 : element ( NULL ),
00010   left    ( NULL ),
00011   right   ( NULL ) { }
00012 
00013 
00014 inline BinNode::BinNode( DBase* e ) 
00015 : element ( e    ),
00016   left    ( NULL ),
00017   right   ( NULL ) { }
00018 
00019 inline BinNode::BinNode( DBase* e, BinNode* l ) 
00020 : element ( e    ),
00021   left    ( l    ),
00022   right   ( NULL ) { }
00023 
00024 
00025 inline BinNode::BinNode( DBase* e, BinNode* l, BinNode* r ) 
00026 : element ( e ), 
00027   left    ( l ),  
00028   right   ( r ) { }
00029 
00030 BinNode::~BinNode() { }
00031 
00032 int BinNode::CompareID( String& ID )  const 
00033 {
00034   if ( this == NULL ) 
00035   {
00036     cout << "The Node is NULL" << endl;
00037     return 1000;
00038   }
00039 
00040   if ( element != NULL ) 
00041   {
00042     if ( element->_id != NULL ) 
00043     {
00044       return -1 *( element->_id->compare( ID ) );
00045     } 
00046     else 
00047     {
00048       return -50;
00049     }
00050   } 
00051   else 
00052   {
00053     return -100;
00054   }
00055 }
00056 
00057 inline int BinNode::CompareID( DBase& db )  const 
00058 {
00059   return CompareID( *db._id );
00060 }
00061 
00062 inline BinNode* BinNode::leftchild()  const 
00063 {
00064     return left; 
00065 }
00066 
00067 inline BinNode* BinNode::rightchild() const 
00068 {
00069     return right; 
00070 }
00071 
00072 inline bool BinNode::valid() const   // Return TRUE if element is not NULL
00073 {
00074   return ( element != NULL );
00075 }
00076 
00077 DBase& BinNode::value() 
00078 { 
00079   if ( this == NULL ) 
00080   {
00081     DBase* temp = new DBase();
00082     cout << "The Node is NULL" << endl;
00083     return *temp;
00084   }
00085   
00086   return *element; 
00087 }
00088 
00089 DBase* BinNode::getElem() 
00090 {
00091   if ( this == NULL ) 
00092   {
00093     cout << "The Node is NULL" << endl;
00094     return NULL;
00095   }
00096   
00097   return element; 
00098 }
00099 
00100 inline void BinNode::setValue( DBase& val ) 
00101 { 
00102   element = new DBase( val ); 
00103 }
00104 
00105 inline bool BinNode::isLeaf() const        // Return TRUE if is a leaf
00106 {
00107   return (left == NULL) && (right == NULL); 
00108 }
00109 
00110 void* BinNode::operator new(size_t) 
00111 {
00112   if (freelist == NULL) 
00113     return(::new BinNode);
00114 
00115   BinNode* temp = freelist;
00116   freelist = freelist->left;
00117   return temp;
00118 }
00119 
00120 void BinNode::operator delete(void* ptr) 
00121 {
00122   ((BinNode*)ptr)->left = freelist;
00123   freelist = (BinNode*)ptr;
00124 }

Generated on Sun Oct 14 18:46:17 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001