void BinarySearchTree::calcDepth(BinaryNode* t, int depth)
{
	if (t != NULL)
	{
		calcDepth(t->left, depth + 1);
		t->searchCost = depth;
		calcDepth(t->right, depth + 1);
	}
}
void calcDepth( const STreeNode* node, int* curDepth, int* depth ) {
   if( !node )
      return;
   if( ++(*curDepth) > *depth )
      *depth = *curDepth;
   if( node->left )
      calcDepth( node->left, curDepth, depth );
   if( node->right )
      calcDepth( node->right, curDepth, depth );
   (*curDepth)--;
}
void STreeSuite_TestInsert( STreeSuiteData* data ) {
   int depth = 0, curDepth = 0;
   int i_i;

   for( i_i = 0; i_i < 15; i_i++ )
      STree_Insert( data->sTree, &i_i );
   pcu_check_true( STree_GetSize( data->sTree ) == 15 );
   pcu_check_true( (calcDepth( STree_GetRoot( data->sTree ), &curDepth, &depth), depth) == 4 );
}
Exemple #4
0
void DFA::findSCCs(){
    SCC scc(nStates);
    State *s;

    for(s = head; s; s = s->next){
        s->depth = 0;
        s->link = NULL;
    }

    for(s = head; s; s = s->next)
        if(!s->depth)
            scc.traverse(s);

    calcDepth(head);
}
void FluidSystem::depthSort()
{
	float *dPos;
	m_dPos = (float *)mapGLBufferObject(&m_cuda_posvbo_resource);

	m_indices.map();

	// calculate depth

	calcDepth(m_dPos, m_sortKeys.getDevicePtr(), m_indices.getDevicePtr(), m_sortVector, m_numParticles);

	// radix sort

	//sortParticlesKey(m_sortKeys.getDevicePtr(), m_indices.getDevicePtr(), m_numParticles);

	unmapGLBufferObject(m_cuda_posvbo_resource);
	m_indices.unmap();
}
// depth sort the particles
void
ParticleSystem::depthSort()
{
    if (!m_doDepthSort)
    {
        return;
    }

    m_pos.map();
    m_indices.map();

    // calculate depth
    calcDepth(m_pos.getDevicePtr(), m_sortKeys.getDevicePtr(), m_indices.getDevicePtr(), m_sortVector, m_numParticles);

    // radix sort
    sortParticles(m_sortKeys.getDevicePtr(), m_indices.getDevicePtr(), m_numParticles);

    m_pos.unmap();
    m_indices.unmap();
}
Exemple #7
0
		/**
			Retain size and translate to a new center location.
		*/
		inline void setCenter( const Vector3& newCenterLoc )
		{
			Vector3 halfSize = Vector3( calcWidth(), calcHeight(), calcDepth() ) * 0.5f ;
			m_Min = newCenterLoc - halfSize;
			m_Max = newCenterLoc + halfSize;
		}
Exemple #8
0
int main(void)
{
    initializeTree();
    while(1)
    {
        printf("1. Insert item. 2. Delete item. 3. Search item. \n");
        printf("4. Print height of tree. 5. Print height of an item. \n");
        printf("6. PrintInOrder. 7. exit.\n");

        int ch;
        scanf("%d",&ch);
        if(ch==1)
        {
            int item;
            scanf("%d", &item);
            insertItem(root, item);
        }
        else if(ch==2)
        {
            int item;
            scanf("%d", &item);
            deleteItem(root, item);
        }
        else if(ch==3)
        {
            int item;
            scanf("%d", &item);
            struct treeNode * res = searchItem(root, item);
            if(res!=0) printf("Found.\n");
            else printf("Not found.\n");
        }
        else if(ch==4)
        {
            int height = calcNodeHeight(root);
            printf("Height of tree = %d\n", height);
        }
        else if(ch==5)
        {
            int item;
            scanf("%d", &item);
            int height = calcHeight(item);
            printf("Height of %d = %d\n", item, height);
        }
        else if(ch==6)
        {
            int h = calcNodeHeight(root);
            printf("\n--------------------------------\n");
            printInOrder(root, h);
            printf("--------------------------------\n");
        }
        else if(ch==7)
        {
            printf("%d\n",getSize(root));
        }
        else if(ch==8)
        {
            int i;
            scanf("%d",&i);
            printf("%d\n",calcDepth(i));
        }
        else if(ch==9)
        {

        }
        else if(ch==10)
        {
            printf("%d\n",getMinItem());
        }
        else if(ch==11)
        {
            printf("%d\n",getMaxItem());
        }
        else if(ch==12)
        {
            int l,r;
            scanf("%d",&l);
            scanf("%d",&r);
            printf("%d\n",rangeSearch(root,l,r));
        }
        else if(ch==6)
        {
            break;
        }
    }

}
int main(void)
{
    initializeTree();
    while(1)
    {
        printf("\n1. Insert item. 2. Delete item. 3. Search item. \n");
        printf("4. Print height of tree. 5. Print height of an item. \n");
        printf("6. PrintInOrder. 7. Calculate Depth 8. get MinItem. 9. get MaxItem.\n10. Range search. 11. Delete. 12. exit.\n");

        int ch;
        scanf("%d",&ch);
        if(ch==1)
        {
            int item;
            scanf("%d", &item);
            insertItem(root, item);
        }
        else if(ch==2)
        {
            int item;
            scanf("%d", &item);
            deleteItem(root, item);
        }
        else if(ch==3)
        {
            int item;
            scanf("%d", &item);
            struct treeNode * res = searchItem(root, item);
            if(res!=0) printf("Found.\n");
            else printf("Not found.\n");
        }
        else if(ch==4)
        {
            int height = calcNodeHeight(root);
            printf("Height of tree = %d\n", height);
        }
        else if(ch==5)
        {
            int item;
            scanf("%d", &item);
            int height = calcHeight(item);
            printf("Height of %d = %d\n", item, height);
        }
        else if(ch==6)
        {
            int h = calcNodeHeight(root);
            printf("\n--------------------------------\n");
            printInOrder(root, h);
            printf("--------------------------------\n");
        }
        else if(ch==12)
        {
            break;
        }
        else if(ch==7)
        {
            int i;
            scanf("%d",&i);
            printf("depth %d\n",calcDepth(i));
        }


        else if(ch==8)
        {
            printf("min item %d\n",getMinItem());
        }
        else if(ch==9)
        {
            printf("max item %d\n",getMaxItem());
        }
        else if(ch==10)
        {
            int item1,item2;
            scanf("%d%d", &item1,&item2);
            printf("Item number %d",rangeSearch(root,item1,item2));

        }
        else if(ch==11)
        {
            int a;
            scanf("%d",&a);
            deleteItem(root,a);
        }
    }

}
int main(void)
{
    //freopen("in2.txt", "r", stdin);
    initializeTree();
    while(1)
    {
        //printMenu();
        int ch;
        scanf("%d",&ch);
        if(ch == 1)
        {
            int item;
            scanf("%d", &item);
            insertItem(root, item);
        }
        else if(ch == 2)
        {
            int item;
            scanf("%d", &item);
            deleteItem(root, item);
        }
        else if(ch == 3)
        {
            int item;
            scanf("%d", &item);
            struct treeNode * res = searchItem(root, item);
            if(res!=0) printf("Found.\n");
            else printf("Not found.\n");
        }
        else if(ch == 4)
        {
            int height = calcNodeHeight(root);
            printf("Height of tree = %d\n", height);
        }
        else if(ch == 5)
        {
            int item;
            scanf("%d", &item);
            int height = calcHeight(item);
            printf("Height of %d = %d\n", item, height);
        }
        else if(ch == 6)
        {
            int h = calcNodeHeight(root);
            printf("\n--------------------------------\n");
            printInOrder(root, h);
            printf("--------------------------------\n");
        }
        else if(ch == 7)
        {
            printf("%d\n", getSize(root));
        }
        else if(ch == 8)
        {
            int item;
            scanf("%d", &item);
            printf("%d\n", calcDepth(item));
        }
        else if(ch == 9)
        {
            printf("%d\n", calcNodeDepth(root));
        }
        else if(ch == 10)
        {
            if(root == 0) {
                printf("tree is empty\n");
                continue;
            }
            printf("%d\n", getMinItem());
        }
        else if(ch == 11)
        {
            if(root == 0) {
                printf("tree is empty\n");
                continue;
            }
            printf("%d\n", getMaxItem());
        }
        else if(ch == 12)
        {
            int left, right;
            scanf("%d %d", &left, &right);
            printf("%d\n", rangeSearch(root, left, right));
        }
        else if(ch == 13)
        {
            int item;
            scanf("%d", &item);
            //printf("Del : %d\n", item);
            //deleteItem(root, item);
            printf("%d\n", deleteItem(root, item));
        }
        else if(ch == 14)
        {
            break;
        }
    }

}
Exemple #11
0
void calcDepthOptimized(float *depth, float *left, float *right, int imageWidth, int imageHeight, int featureWidth, int featureHeight, int maximumDisplacement)
{
	calcDepth(depth, left, right, imageWidth, imageHeight, featureWidth, featureHeight, maximumDisplacement, NULL);
}