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


Digital tree (trie) insertion


trie insert( key, t, depth ) typekey key; trie t; int depth; { int j; trie t1; if ( t==NULL ) return( NewDataNode(key) ); if ( IsData(t) ) if (t->k == key) Error /*** Key already in table ***/; else { t1 = NewIntNode(); t1->p[ charac(depth,t->k) ] = t; t = insert( key, t1, depth ); } else { j = charac(depth,key); t->p[j] = insert( key, t->p[j], depth+1 ); } return( t ); }

C source (344.ins.c)



© Addison-Wesley Publishing Co. Inc.