Changeset 3555 for trunk/kStuff/include/k/kAVLTmpl/kAVLGet.h
- Timestamp:
- Aug 26, 2007, 12:43:27 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kStuff/include/k/kAVLTmpl/kAVLGet.h
r3553 r3555 1 1 /* $Id$ */ 2 2 /** @file 3 * 4 * kAVLGet - get routine for AVL trees. 5 * 6 * Copyright (c) 1999-2002 knut st. osmundsen (bird@anduin.net) 7 * 8 * GPL 3 * kAVLTmpl - Templated AVL Trees, Get a Node. 9 4 */ 10 5 11 #ifndef _kAVLGet_h_ 12 #define _kAVLGet_h_ 6 /* 7 * Copyright (c) 1999-2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 * 9 * This file is part of kStuff. 10 * 11 * kStuff is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Lesser General Public 13 * License as published by the Free Software Foundation; either 14 * version 2.1 of the License, or (at your option) any later version. 15 * 16 * kStuff is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public 22 * License along with kStuff; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 * 25 */ 13 26 14 27 15 28 /** 16 29 * Gets a node from the tree (does not remove it!) 30 * 17 31 * @returns Pointer to the node holding the given key. 18 32 * @param ppTree Pointer to the AVL-tree root node pointer. 19 33 * @param Key Key value of the node which is to be found. 20 * @sketch21 * @status completely implemented.22 * @author knut st. osmundsen23 34 */ 24 PKAVLNODECORE KLIBCALL KAVL_FN(Get)(PPKAVLNODECOREppTree, KAVLKEY Key)35 KAVL_DECL(KAVLNODECORE *) KAVL_FN(Get)(KAVLTREEPTR *ppTree, KAVLKEY Key) 25 36 { 26 K LOGENTRY2("PKAVLNODECORE","PPKAVLNODECORE ppTree, KAVLKEY Key", ppTree, Key);27 #ifndef AVL_CMP28 register PKAVLNODECORE pNode = *ppTree;37 KAVLNODECORE *pNode; 38 if (*ppTree == KAVL_NULL) 39 return NULL; 29 40 30 while (pNode != NULL && AVL_NE(pNode->Key, Key)) 41 pNode = KAVL_GET_POINTER(ppTree); 42 while (KAVL_NE(pNode->Key, Key)) 31 43 { 32 if (AVL_G(pNode->Key, Key)) 33 pNode = pNode->pLeft; 44 if (KAVL_G(pNode->Key, Key)) 45 { 46 if (pNode->pLeft == KAVL_NULL) 47 return NULL; 48 pNode = KAVL_GET_POINTER(&pNode->pLeft); 49 } 34 50 else 35 pNode = pNode->pRight; 51 { 52 if (pNode->pRight == KAVL_NULL) 53 return NULL; 54 pNode = KAVL_GET_POINTER(&pNode->pRight); 55 } 36 56 } 37 38 #else39 40 register int iDiff;41 register PKAVLNODECORE pNode = *ppTree;42 43 while (pNode != NULL && (iDiff = AVL_CMP(pNode->Key, Key)) != 0)44 {45 if (iDiff > 0)46 pNode = pNode->pLeft;47 else48 pNode = pNode->pRight;49 }50 51 #endif52 53 KLOGEXIT(pNode);54 57 return pNode; 55 58 } 56 59 57 58 #endif
Note:
See TracChangeset
for help on using the changeset viewer.