Example #1
0
/* 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;
        }
Example #2
0
bool BSTree::RecursiveInsert(Node* &current, 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);
	}
}
Example #3
0
bool BSTree::Insert(Account* item)
{	
	return RecursiveInsert(root, item);
}
Example #4
0
 KdTree
 Insert( ItemType Item, KdTree T )
 {
     return RecursiveInsert( Item, T, 0 );
 }