[Home]
[Contents]
[Chapter]
[Previous Algorithm]
[Next Algorithm]


K-d tree insertion


tree insert( key, t, lev ) typekey key[]; tree t; int lev; { int i; if ( t==NULL ) t = NewNode( key ); else { for ( i=0; i<K && key[i]==t->k[i]; i++ ); if ( i==K ) Error /*** Key already in table ***/; else if ( key[lev] > t->k[lev] ) t->right = insert( key, t->right, (lev+1)%K ); else t->left = insert( key, t->left, (lev+1)%K ); } return( t ); };

C source (352.ins.c)



© Addison-Wesley Publishing Co. Inc.