void insertleaf(node *leaf,node *root) { assert(root); printf("Presently at %d\n",root->data); if(!root->lchild) { printf("Left subtree: No subtree\n"); } else { printf("Left subtree: Exist\n"); } if(!root->rchild) { printf("Right subtree: No right subtree\n"); } else { printf("Right subtree : Exist\n"); } printf("Options\n L. Insert at left\nR. Insert at right.\n l. move to left subtree \n r. move to right subtree\n=>"); char ch; fflush(stdin); scanf("%c",&ch); switch(ch) { case 'L': root->lchild=leaf;break; case 'R': root->rchild=leaf;break; case 'l': insertleaf(leaf,root->lchild);break; case 'r': insertleaf(leaf,root->rchild);break; default:printf("invalid operation");getchar(); } printf("---------\n"); }
btDbvtNode* btDbvt::insert(const btDbvtVolume& volume,void* data) { btDbvtNode* leaf=createnode(this,0,volume,data); insertleaf(this,m_root,leaf); ++m_leaves; return(leaf); }
int main() { node *root=createnode(1); for(int i=2;i<100;i++) { system("cls"); insertleaf(createnode(i),root); } return 0; }
void btDbvt::update(btDbvtNode* leaf,int lookahead) { btDbvtNode* root=removeleaf(this,leaf); if(root) { if(lookahead>=0) { for(int i=0;(i<lookahead)&&root->parent;++i) { root=root->parent; } } else root=m_root; } insertleaf(this,root,leaf); }
void btDbvt::update(btDbvtNode* leaf,btDbvtVolume& volume) { btDbvtNode* root=removeleaf(this,leaf); if(root) { if(m_lkhd>=0) { for(int i=0;(i<m_lkhd)&&root->parent;++i) { root=root->parent; } } else root=m_root; } leaf->volume=volume; insertleaf(this,root,leaf); }