Example #1
0
	int findMaxValue(tree *root)
	{
	int root_val,left,right,max;
	if(root != NULL){
	root_val=root->data;
	
	left=findMaxValue(root->left);
	right=findMaxValue(root->right);
	
	if(left > right)
	max=left;
	else
	max=right;
	
	if(root_val > max)
	max=root_val;
	return max;
	}
	}
void BST::findMaxValue(PTree * toDel, PTree * toDelParent, PTree lessThanParent, PTree lessThan) const
{
    if (lessThan == NULL)
    {
        * toDel = NULL;
    }
    if (lessThan->pRight) {
        return findMaxValue(toDel, toDelParent, lessThan, lessThan->pRight);
    }
    else
    {
        * toDel = lessThan;
        * toDelParent = lessThanParent;
        return;
    }
}
Example #3
0
    //-------------------------------------------------------------------------
    //! @brief This is the callback function which is passed to the Signal in
    //! the model's constructor.
    //!
    //! Here the value is retrieved and appended to the list. If the list is too
    //! large, the oldest value is removed. The Validity is updated, and the
    //! Signal is emitted, telling others that the values have been updated.
    //!
    //! @todo Make the 'average value' calculation more efficient.
    //-------------------------------------------------------------------------
    void ValueList::update()
    {
        variant tmp_value( retrieve_value__() );
        // Make tmp_average the same 'type' as tmp_value and set it to '0'.
        variant tmp_average = tmp_value;
        tmp_average.zero();

        if( max_value__.isEmpty() )
        {
            max_value__ = tmp_value;
            max_value__.zero();
        }

        values__.push_back( tmp_value );
        if( values__.size() > list_size__ )
            values__.pop_front();

        std::for_each( values__.begin()
                     , values__.end()
                     , [&]( variant const& _var )
        {
            tmp_average = tmp_average + _var;
        } );
        average_value__ = tmp_average / values__.size();

        if( tmp_value > max_value__ )
        {
            max_value__         = tmp_value;
            max_value_position__ = 0;
        }
        else
            ++max_value_position__;

        if( max_value_position__ >= list_size__ )
            findMaxValue();

        validity__ = Validity::ENABLED;

        signal__->emit();
    }
Example #4
0
void canny(FILE* inputImageFile, FILE* outputMagnitudes, FILE* outputPeaks, FILE* outputFinal, double sigma){
    Mask mask;
    int picBuffer[PICSIZE][PICSIZE];
    double itsMagnitudes[PICSIZE][PICSIZE];
    double maxMagnitude;
    GradientVector usingGradients;
    double peaks[PICSIZE][PICSIZE];
    double final[PICSIZE][PICSIZE];

    readImageTo(picBuffer, inputImageFile);
    mask = generateSmoothenerMask(sigma);
    usingGradients = calculateGradients(picBuffer, mask);
    calculateMagnitudes(usingGradients, mask.radius, itsMagnitudes);
    maxMagnitude = findMaxValue(itsMagnitudes);
    scaleImageWithRespectTo(maxMagnitude, itsMagnitudes);

    findPeaks(itsMagnitudes, usingGradients, mask.radius, peaks);
    Threshold threshold = getThreshold(itsMagnitudes);
    applyHysteresisThresholdTo(itsMagnitudes, usingGradients, mask.radius, 
                                peaks, threshold, final);
    writeTo(outputMagnitudes, itsMagnitudes);
    writeTo(outputPeaks, peaks);
    writeTo(outputFinal, final);
}
bool BST::remove(PTree * pTree, DATA data)
{
    if (*pTree == NULL)
    {
        return false;
    }
    if ((*pTree)->data == NULL)
    {
        return false;
    }
    
    int result = m_fCmp((*pTree)->data, data);
    
    if (result == 0)
    {
        // No child, just delete
        if ((*pTree)->pLeft==NULL && (*pTree)->pRight==NULL)
        {
            return m_fRemove(&(*pTree)->data);
        }
        // No Left
        else if ((*pTree)->pLeft==NULL)
        {
            if (m_fRemove(&(*pTree)->data))
            {
                PTree pToDel = (*pTree);
                *pTree = (*pTree)->pRight;
                delete pToDel;
                return true;
            }
            return false;
            
        }
        // No right
        else if ((*pTree)->pRight == NULL)
        {
            if (m_fRemove(&(*pTree)->data))
            {
                PTree pToDel = (*pTree);
                *pTree = (*pTree)->pLeft;
                delete pToDel;
                return true;
            }
            return false;
            
        }
        else
        {
            if (m_fRemove(&(*pTree)->data))
            {
                PTree pToDel = NULL;
                PTree pToDelParent = NULL;
                
                findMaxValue(&pToDel, &pToDelParent, (*pTree), (*pTree)->pLeft);
                Tree temp = *(*pTree);
                pToDel->pRight = temp.pRight;
                pToDelParent->pRight = pToDel->pLeft;
                pToDel->pLeft = pToDel==temp.pLeft ? pToDel->pLeft : temp.pLeft;
                
                delete (*pTree);
                *pTree = pToDel;
                
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    else if (result > 0)
    {
        remove(&(*pTree)->pLeft, data);
    }
    else
    {
        remove(&(*pTree)->pRight, data);
    }
    
    return true;
}
Example #6
0
/*		Main Function of Binary tree		*/
int main()
{
	int ch,f,data;
	tree *root;
	root=createTree();
	
	queue *Q;
	Q=create();
	
		    while(1){
	
	               printf("\n<1> Insert,  ");
	               printf("<2> Delete , ");
         	       printf("<3> PreOrder,  ");
	 	       printf("<4> InOrder, \n");
	 	       printf("<5> PostOrder,");
         	       printf("<6> Delete Tree");
         	       printf("<7> Height/Depth of tree, \n ");
         	       printf("<8> Maximum Node, ");
         	       printf("<9> Total Nodes Of Tree, ");
         	       printf("<10>LevelOrder traversal\n");
         	       printf("<0>Exit, Choice: ");
         	       scanf("%d",&ch);

		switch(ch){
			case 1:
				printf("\tNode Value :");
				scanf("%d",&data);
				
				Insert(&root,data);
				break;
			case 2:
				printf("\tNode To Delete :");
				scanf("%d",&data);
				f=Delete(&root,data);
				if(f)
				printf("Deleted Node:%d\n",f);
				break;		
			case 3:
				Preorder(root);
				break;
			case 4:
				Inorder(root);
				break;
			case 5:
				Postorder(root);
				break;
			case 6:
				DeleteTree(root);
				root=createTree();
				break;
			case 7:
				f=heightOfBinary(root);
			printf("\n(Non-recursive)Height/Depth OfBinary : %d\n",f);
		//		f=depthOfBinary(root);
		//	printf("(Recursive)Height/Depth OfBinary : %d\n",f);
				break;
				
			case 8:
				f=findMaxValue(root);
				printf("Maximum Value OfBinary : %d\n",f);
				break;
			case 9:
				f=sizeOfBinary(root);
				printf("Number of Nodes: %d\n",f);
				break;
			case 10:
				printf("\n");
				f=LevelOrderTraverse(root);
			printf("\n\nNumber of Nodes : %d\n",f);
			break;
			case 0:
				DeleteTree(root);
				 exit(0);
				 break;
			default :
			printf("\tInvalid Choice\n");
			}
		}
	}