//----------------------------------------------------------------------------- // Copyright © 2003 - Philip Howard - All rights reserved // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //----------------------------------------------------------------------------- // package libh/avl // homepage http://libh.slashusr.org/ //----------------------------------------------------------------------------- // author Philip Howard // email libh at ipal dot org // homepage http://phil.ipal.org/ //----------------------------------------------------------------------------- // This file is best viewed using a fixed spaced font such as Courier // and in a display at least 120 columns wide. //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // G. M. Adelson-Velskii and E. M. Landis are the inventors of the algorithm // bearing their initials, AVL. Their algorithm for height-balanced binary // search trees is the basis of the code in this package. Some modification // is made to the balancing operations, and features are added for practical // purposes. //----------------------------------------------------------------------------- #include "avl_lib.h" __PROTO_BEGIN__ //----------------------------------------------------------------------------- // function avl_first // // purpose Find the first node with the lowest key value from the given // binary tree. // // arguments 1 (AVL *) pointer to binary tree // // returns (void *) pointer to the first node // (void *) NULL if the binary tree is empty //----------------------------------------------------------------------------- void * avl_first ( AVL * arg_tree ) __PROTO_END__ { avl_link * link_p ; #ifdef AVL_CHECK_ARGS if ( ! arg_tree ) return NULL; #endif //---------------------------------- // Find the lowest node in the tree. //---------------------------------- if ( ! ( link_p = arg_tree->link.hi ) ) return NULL; while ( link_p->lo ) link_p = link_p->lo; arg_tree->select = link_p; return avl_link_to_node( arg_tree, link_p ); }