/* START: fig12_43.txt */ static KdTree RecursiveInsert( ItemType Item, KdTree T, int Level ) { if( T == NULL ) { T = malloc( sizeof( struct KdNode ) ); if( T == NULL ) FatalError( "Out of space!!!" ); T->Left = T->Right = NULL; T->Data[ 0 ] = Item[ 0 ]; T->Data[ 1 ] = Item[ 1 ]; } else if( Item[ Level ] < T->Data[ Level ] ) T->Left = RecursiveInsert( Item, T->Left, !Level ); else T->Right = RecursiveInsert( Item, T->Right, !Level ); return T; }
bool BSTree::RecursiveInsert(Node* ¤t, Account* item) { if (current == NULL) { current = new Node(); current->pAcct = item; return true; } if (*(current->pAcct) == *item) { return false; } else if(*item > *(current->pAcct)) { return RecursiveInsert(current->right, item); } else if (*item < *(current->pAcct)) { return RecursiveInsert(current->left, item); } }
bool BSTree::Insert(Account* item) { return RecursiveInsert(root, item); }
KdTree Insert( ItemType Item, KdTree T ) { return RecursiveInsert( Item, T, 0 ); }