/* Implementacija skupa pomocu binarnih stabala */ /* Ovde je potrebno da znamo da li je jedan kljuc manji, jednak ili veci od drugog kljuca */ extern int KeyCmp( void *a, void *b ); /* Vraca -1, 0, 1 za a < b, a == b, a > b */ void *FindInTree( Node t, void *key ) { if ( t == (Node)0 ) return NULL; switch( KeyCmp( key, ItemKey(t->item) ) ) { case -1 : return FindInTree( t->left, key ); case 0: return t->item; case +1 : return FindInTree( t->right, key ); } } void *FindInCollection( collection c, void *key ) { /* Trazi objekat u skupu Pre-uslovi: (c je skup kreiran pozivom ConsCollection) && (key != NULL) Post-uslovi: vraca objekat identifikovan kljucem ako takav postoji, u suprotnom vraca NULL */ assert( c != NULL ); assert( key != NULL ); /* Pocni pretragu sa cvorom na vrhu liste */ return FindInTree( c->root, key ); }