1- /* $Id$ */
2-
1+ #include < stdlib.h>
2+ #include < stdio.h>
3+ #include < string.h>
34#include < alloc.h>
5+ #include " avl.h"
46
57/* Implementation of AVL-trees: trees in which the difference in depth
68 of the left branch and the right branch is at most one.
@@ -29,18 +31,19 @@ struct avl_node
2931struct avl_tree
3032{
3133 struct avl_node * root; /* root of the avl tree */
32- int (*cmp)(AVLtree * x, AVLtree * y); /* address of comparison routine */
34+ int (*cmp)(char * x, char * y); /* address of comparison routine */
3335};
3436/* create definitions for new_avl_tree() and free_avl_tree() */
3537/* STATICALLOCDEF "avl_tree" 2 */
3638
3739/* The next routine adds a node to an avl tree. It returns 1 if the
3840 tree got deeper.
3941*/
40- static int balance_add (ppsc, n, cmp)
41- struct avl_node** ppsc; /* address of root */
42- char * n; /* user-supplied information */
43- int (*cmp)(); /* user-supplied comparison routine */
42+ static int balance_add (
43+ struct avl_node ** ppsc /* address of root */ ,
44+ char * n /* user-supplied information */ ,
45+ int (*cmp)(char * x, char * y) /* user-supplied comparison routine */
46+ )
4447{
4548 struct avl_node *psc = *ppsc, *qsc, *ssc;
4649
@@ -165,7 +168,7 @@ int (*cmp)(); /* user-supplied comparison routine */
165168/* extern struct avl_tree *create_avl_tree(int (*cmp)());
166169 Returns a fresh avl_tree structure.
167170*/
168- struct avl_tree * create_avl_tree (cmp) int (*cmp)(); /* comparison routine */
171+ struct avl_tree * create_avl_tree (int (*cmp)(char * x, char * y) /* comparison routine */ )
169172{
170173 struct avl_tree * p = new_avl_tree ();
171174
@@ -176,8 +179,7 @@ struct avl_tree* create_avl_tree(cmp) int (*cmp)(); /* comparison routine */
176179/* extern add_to_avl_tree(struct avl_tree *tree, char *n);
177180 Adds the information indicated by 'n' to the avl_tree indicated by 'tree'
178181*/
179- add_to_avl_tree (tree, n) struct avl_tree* tree; /* tree to be added to */
180- char * n; /* information */
182+ void add_to_avl_tree (struct avl_tree * tree /* tree to be added to */ , char * n /* information */ )
181183{
182184 (void )balance_add (&(tree->root ), n, tree->cmp );
183185}
@@ -186,9 +188,9 @@ char* n; /* information */
186188 Returns the information in the largest node that still compares <= to 'n',
187189 or 0 if not present.
188190*/
189- char * find_ngt (tree, n)
190- struct avl_tree* tree; /* tree to be searched in */
191- char * n; /* information to be compared with */
191+ char * find_ngt (
192+ struct avl_tree * tree /* tree to be searched in */ ,
193+ char * n /* information to be compared with */ )
192194{
193195 struct avl_node *nd = tree->root , *lastnd = 0 ;
194196
@@ -213,9 +215,9 @@ char* n; /* information to be compared with */
213215 Returns the information in the largest node that still compares >= to 'n',
214216 or 0 if not present.
215217*/
216- char * find_nlt (tree, n)
217- struct avl_tree* tree; /* tree to be searched in */
218- char * n; /* information to be compared with */
218+ char * find_nlt (
219+ struct avl_tree * tree /* tree to be searched in */ ,
220+ char * n /* information to be compared with */ )
219221{
220222 struct avl_node *nd = tree->root , *lastnd = 0 ;
221223
@@ -240,9 +242,9 @@ char* n; /* information to be compared with */
240242 Returns the information in the node that compares equal to 'n',
241243 or 0 if not present.
242244*/
243- char * find_eq (tree, n)
244- struct avl_tree* tree; /* tree to be searched in */
245- char * n; /* information to be compared with */
245+ char * find_eq (
246+ struct avl_tree * tree /* tree to be searched in */ ,
247+ char * n /* information to be compared with */ )
246248{
247249 struct avl_node * nd = tree->root ;
248250
0 commit comments