00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 // -*-C++-*- 00037 00044 #ifndef __GNUC__ 00045 // Implementation stuff included here because g++ 00046 // (rightly) doesn't do implicit .cxx file inclusion. 00047 00048 #include <sys/types.h> 00049 #include "stdlib.h" 00050 #include "btree.h" 00051 00052 00053 template <class BINARY_NODE> 00054 BINARY_TREE_NODE<BINARY_NODE>* BINARY_TREE_NODE<BINARY_NODE>:: 00055 Enter(BINARY_NODE node, MEM_POOL *pool) 00056 { 00057 //typedef BINARY_TREE_NODE<BINARY_NODE> THIS_NODE; 00058 //typedef BINARY_TREE_NODE<BINARY_NODE> *THIS_NODEP; 00059 //THIS_NODEP nodep = this; 00060 BINARY_TREE_NODE<BINARY_NODE> *nodep = this; 00061 BOOL found = FALSE; 00062 while (!found) { 00063 if (nodep->_data == node) { 00064 found = TRUE; 00065 } else if (node < nodep->_data) { 00066 if (!nodep->_left) { 00067 nodep->_left = CXX_NEW(BINARY_TREE_NODE<BINARY_NODE>(node),pool); 00068 found = TRUE; 00069 } 00070 nodep = nodep->_left; 00071 } else { 00072 if (!nodep->_right) { 00073 nodep->_right = CXX_NEW(BINARY_TREE_NODE<BINARY_NODE>(node),pool); 00074 found = TRUE; 00075 } 00076 nodep = nodep->_right; 00077 } 00078 } 00079 return nodep; 00080 } 00081 00082 00083 template <class BINARY_NODE> 00084 BINARY_TREE_NODE<BINARY_NODE>* BINARY_TREE_NODE<BINARY_NODE>:: 00085 Find(BINARY_NODE node) const 00086 { 00087 //typedef BINARY_TREE_NODE<BINARY_NODE> *THIS_NODEP; 00088 BINARY_TREE_NODE<BINARY_NODE> *nodep = (BINARY_TREE_NODE<BINARY_NODE> *)this; 00089 while (1) { 00090 if (nodep->_data == node) { 00091 return nodep; 00092 } else if (node < nodep->_data) { 00093 if (nodep->_left) { 00094 nodep = nodep->_left; 00095 } else { 00096 return NULL; 00097 } 00098 } else { 00099 if (nodep->_right) { 00100 nodep = nodep->_right; 00101 } else { 00102 return NULL; 00103 } 00104 } 00105 } 00106 } 00107 00108 #endif
1.5.6