예제 #1
0
/*!
 * \brief Cleans up the object and frees up memory used by the solution tree.
 * \param processEvents If set to \c true then \link QCoreApplication::processEvents() QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents)\endlink will be called from time to time while cleaning up.
 * \warning After call to this function a solution tree returned by the solve() function is no longer valid.
 * \note It is not required to call this function manually. This function is always called by solve() at the beginning of the solution process.
 *
 * \sa solve(), setCleanupOnCancel()
 */
void CTSPSolver::cleanup(bool processEvents)
{
    route.clear();
    mayNotBeOptimal = false;
    if (root != NULL)
        deleteTree(root, processEvents);
}
MathExpr * mathexpr_create(char *formula, int (*getVar) (char *))
{
    ExprTree *tree;
    MathExpr *expr = NULL;
	MathExpr *result = NULL;
    getVariableIndex = getVar;
    Err = 0;
    PrevLex = 0;
    CurLex = 0;
    S = formula;
    Len = strlen(S);
    Pos = 0;
    Bc = 0;
    tree = getTree();
    if (Bc == 0 && Err == 0)
	{
		traverseTree(tree, &expr);
		while (expr)
		{
			result = expr;
			expr = expr->prev;
		}
	}
	deleteTree(tree);
    return result;
}
예제 #3
0
파일: BST.cpp 프로젝트: haydenx83/School
//traverse list inorder and add elements to the array
int BST::sortHelper(TreeItemType a[], int i, TreeNode* t)
{
	TreeNode* curr = t;
        TreeItemType x;

        if(t->leftChildPtr != NULL)
        {
            curr = curr->leftChildPtr;
            sortHelper(a,i,curr);
        }

        x = curr->item;
        a[i] = x;
	i++;

        if(t->rightChildPtr != NULL)
        {
            curr = curr->rightChildPtr;
            sortHelper(a,i,curr);
        }
	if(i == (size() - 1))
	{
	    int j,k;
	    deleteTree(root);
	    j = sizeof(a);
	    k = ceil(j/2);

		buildHelper(a,k,0,j-1,root);
	}
}
/*
void MovieTree::deleteTree(Movie*)

Description:
Private, recursive function called in the destructor to properly deallocate
memory used by the tree.

Precondition:
The ends of the tree are nil.

Postcondition:
Each movie in the tree is deleted, using post-order traversal.
*/
void MovieTree::deleteTree(Movie *m)
{
    if (m == nil) {
        return;
    }

    if (m->left != nil) {
        deleteTree(m->left);
    }

    if (m->right != nil) {
        deleteTree(m->right);
    }

    delete m;
}
예제 #5
0
//! destructor
COctTreeSceneNode::~COctTreeSceneNode()
{
	//if (Mesh)
	//	Mesh->drop();

	deleteTree();
}
예제 #6
0
main()
{
	struct node *T;
	root =NULL;
	T=root;
	insert(root,5);
	insert(root,9);
	insert(root,4);
	insert(root,5);
	insert(root,2);
	insert(root,2);
	insert(root,7);

	traverseAndDisplay(root);

	deleteNode(root,5);
	traverseAndDisplay(root);
	
	deleteNode(root,2);
	traverseAndDisplay(root);

	deleteTree(root);
	traverseAndDisplay(root);
	return 0;
}
예제 #7
0
void clean_up(RBTree *tree)
{
  if ( tree != NULL )
  {
    deleteTree(tree);
    free(tree);
  }
}
예제 #8
0
파일: lexicon.cpp 프로젝트: chuzui/courses
void Lexicon::deleteTree(TrieNode* node) {
    if (node != NULL) {
        for (char letter = 'a'; letter <= 'z'; letter++) {
            deleteTree(node->child(letter));
        }
        delete node;
    }
}
예제 #9
0
void Profiler::deleteTree( Node* node )
{
	for (auto it = node->children.begin(); it != node->children.end(); ++it)
	{
		deleteTree(*it);
	}
	delete node;
}
	static void deleteTreeAr( std::vector<TreeNode*>& ar)
	{
		std::vector<TreeNode*>::iterator ai = ar.begin(), ae = ar.end();
		for (; ai != ae; ++ai)
		{
			deleteTree( *ai);
		}
	}
예제 #11
0
void deleteTree(treenode_t ** root_ptr) {
    if (*root_ptr == NULL) {
        return;
    }
    else {
        // go left first
        deleteTree(&(*root_ptr)->left);

        // go right second
        deleteTree(&(*root_ptr)->right);

        // delete root
        (*root_ptr)->left = NULL;
        (*root_ptr)->right = NULL;
        free (*root_ptr);
        (*root_ptr) = NULL;
    }
}
예제 #12
0
void deleteTree(node * root)
{
	for(int i=0;i<10;i++)
	{
		if(root->child[i])
			deleteTree(root->child[i]);
	}
	delete root;
}
예제 #13
0
파일: BST.hpp 프로젝트: Elblonko/CSE100
  virtual ~BST() {

    //Call to clear
    deleteTree(root);

    //set root equal to nullptr
    root = nullptr;

  }
예제 #14
0
파일: BST.hpp 프로젝트: Elblonko/CSE100
 void clear() {
   
     //Delete the tree Post Order Traversal
     deleteTree(root);
   
     //Set root to nullptr
     root = nullptr;
   
 }
예제 #15
0
void KDTree::rebuildTree(vector<Drawable *> objList) {
    assert(objList.size() > 0);

    deleteTree(this->root);
    root = new KDNode;
    root->objects = objList;
    bounds = findBounds(objList);
    buildTree(root, bounds, 0);
}
예제 #16
0
KDTree & KDTree::operator=(const KDTree &other) {
    if(this != &other) {
        deleteTree(this->root);
        this->root = copyTree(other.root);
        this->bounds = other.bounds;
    }

    return *this;
}
예제 #17
0
파일: wrapper.cpp 프로젝트: cran/msBP
// compute the cdf given a tree
void pmsBP_C(double *weights, double * grid, int * ngrid, int *maxS, double * out, int *log_p)
{
	struct bintree *w = new struct bintree;
	setTree(1.0, w);
	//struct bintree *w = newtree(1);
	array2tree(weights, maxS[0], w);
	pmsBP(w, out, grid, ngrid, log_p);
	deleteTree(w);
}
예제 #18
0
파일: wrapper.cpp 프로젝트: cran/msBP
// random sample from a msBP density
void rsample_msBP_C(int *N, double * Rvec, double *Svec, double *a, double *b, int * maxS, double *ans)
{
	int i = 0;	
	struct bintree * Stree = new struct bintree;
	struct bintree * Rtree = new struct bintree;
	setTree(1.0, Stree);
	setTree(1.0, Rtree);
	//struct bintree *Stree = newtree(1);
	//struct bintree *Rtree = newtree(1);
	array2tree(Svec, maxS[0], Stree);
	array2tree(Rvec, maxS[0], Rtree);
	for(i=0; i<N[0]; i++)
	{
		ans[i] = rsample_msBP(Rtree,Stree,a[0],b[0]);
	}
	deleteTree(Rtree);
	deleteTree(Stree);
}
예제 #19
0
파일: wrapper.cpp 프로젝트: cran/msBP
// compute the weigths given a tree 
void computeprob_C(double *S, double * R, int *maxS, double *a, double *b, double *ans, int *root)
{
	struct bintree *Stree = new struct bintree;
	struct bintree *Rtree = new struct bintree;
	setTree(1.0, Stree);
	setTree(1.0, Rtree);
///	struct bintree *Stree = newtree(1);
//	struct bintree *Rtree = newtree(1);
//	struct bintree *anstree = newtree(1);
	if(root[0]==0) S[0] = 0;
	array2tree(S, maxS[0], Stree);
	array2tree(R, maxS[0], Rtree);
	struct bintree *anstree = computeprob(Stree, Rtree, a[0], b[0], maxS[0], 1);
	tree2array(anstree, ans, maxS[0], 0);
	deleteTree(Stree);
	deleteTree(Rtree);
	deleteTree(anstree);
} 
예제 #20
0
파일: wrapper.cpp 프로젝트: cran/msBP
//compute the posterior cluster allocation with slice sampler [Algorithm 2]
void postCluster_C(int *s, int *h, double *y, double *pi, int *maxS, int *N, int *printscreen)
{
	struct bintree *pitree = new struct bintree;
	setTree(1.0, pitree);
	//struct bintree *pitree = newtree(1);
	array2tree(pi, maxS[0], pitree);
	postCluster(s, h, y, pitree, *maxS, *N, *printscreen);
	deleteTree(pitree);
} 
예제 #21
0
void SelectableFilesModel::buildTreeFinished()
{
    beginResetModel();
    deleteTree(m_root);
    m_root = m_rootForFuture;
    m_rootForFuture = 0;
    endResetModel();
    emit parsingFinished();
}
예제 #22
0
RBTree * loadTree(char *filename){
	RBTree *tree = malloc(sizeof(RBTree));
	initTree(tree);

	FILE *fp;
	fp = fopen(filename, "r");
	if(!fp){

		deleteTree(tree);
		free(tree);
		return NULL;
	}
	
	int sizeDb, numNodes = NULL;
	fread( &(sizeDb), sizeof(int), 1, fp );
	fread( &(numNodes), sizeof(int), 1, fp );
	if(numNodes == 0){
		fclose(fp);
		deleteTree(tree);
		free(tree);
		return NULL;
	}

	int i;
	for(i=0; i< numNodes; i++){
		RBData *data = malloc(sizeof(RBData));
		int length = NULL;

		fread(&(length), sizeof(int), 1, fp);
		data->primary_key = malloc(sizeof(char) * (length+1) );
		fread(data->primary_key, sizeof(char), length, fp);
		data->primary_key[length] = '\0';

		fread(&(data->numFiles), sizeof(int), 1, fp);
		data->numTimes = malloc(sizeof(int) * sizeDb);
		fread(data->numTimes, sizeof(int), sizeDb, fp);

		insertNode(tree, data);
	}

	fclose(fp);
	return tree;
}
예제 #23
0
void AutoFocus::deleteTree(treeNode* root) 
{

	if (root->left != NULL)
		deleteTree(root->left);

	if (root->right != NULL)
		deleteTree(root->right);

	std::map<report_enum,af_attribute*>::iterator iter = root->data.m_attributes.begin();

	while (iter != root->data.m_attributes.end())	
	{
		delete (iter->second);	
		iter++;
	}
	delete root;
	return;
}
예제 #24
0
void Struktur::deleteTree (IContainerObject *o)
{
        ICnrObjectSet set = immediateDescendentsOf (o);
        ICnrObjectSet::Cursor cur (set);
        forCursor (cur)
        {
                deleteTree (cur.element ());
                delete cur.element ();
        }
}
void test(){
    node *t1 = buildTree(NULL,3,0,0.5);
    node *t2 = buildTree(NULL,3,0,0.5);
    writeTree(t1,"TreeOne.dot");
    writeTree(t2,"TreeTwo.dot");
    /*
    mutate(t1,0.8);
    mutate(t2,0.8);
    writeTree(t1,"TreeOneMutate.dot");
    writeTree(t2,"TreeTwoMutate.dot");
    */
    
    swap(t1,t2,1);
    writeTree(t1,"TreeOneSwap.dot");
    writeTree(t2,"TreeTwoSwap.dot");

    deleteTree(t1);
    deleteTree(t2);
}
예제 #26
0
		void ObstacleKDTree::buildTree( const std::vector< Obstacle * > obstacles ) {
			deleteTree();
			
			_obstacles.assign( obstacles.begin(), obstacles.end() );
			if ( _obstacles.size() > 0 ) {
				std::vector< Obstacle * > temp;
				temp.assign( _obstacles.begin(), _obstacles.end() );
				_tree = buildTreeRecursive( temp );
			}
		}
예제 #27
0
void Profiler::cleanup()
{
	stop();
	auto it = m_profilingTrees.begin();
	for (; it != m_profilingTrees.end(); ++it)
	{
		deleteTree(it->second->root);
		delete it->second;
	}
	m_profilingTrees.clear();
}
예제 #28
0
파일: vis.c 프로젝트: Primer42/BowdoinCS350
unsigned int process_event_list(DataSet *terrain, GridPoint start,
                                SweepEvent *event_list, size_t len,
                                DataSet *vshed)
{
  SweepEvent *eptr, *eend;
  RBTree *tree;
  TreeNode *node;
  TreeValue value;
  unsigned int count;
  double h0, h1;
  
  // retrieve height of start point
  gpHeight(terrain, start, h0);
  // initialiaze tree
  value.key = 0;
  value.gradient = SMALLEST_GRADIENT;
  tree = createTree(value);

  // process list
  count = 0;
  eptr = event_list;
  eend = event_list + len;
  while (eptr < eend) {
    if (eptr->event == ENTER_EVENT) {
      // set key to node distance
      value.key = eptr->dist;
      // calculate slope in z
      gpHeight(terrain, eptr->p, h1);
      value.gradient = (h1 - h0) / eptr->dist;
      // insert the node into the active list
      insertInto(tree, value);
      
    }else if (eptr->event == SIGHT_EVENT) {
      // check the active list if the current node is visible
      // query for the current node
      node = searchForNodeWithKey(tree, eptr->dist);
      assert(notNIL(node));
      h1 = findMaxGradientWithinKey(tree, eptr->dist);
      if (vshed != NULL)
        dSet(vshed, eptr->p.r, eptr->p.c, (node->value.gradient >= h1));
      count += (node->value.gradient >= h1);

    }else { // LEAVE_EVENT 
      // remove the current node
      deleteFrom(tree, eptr->dist);

    }
    eptr++;
  }
  // garbage collect
  deleteTree(tree);

  return count;
}
//! destructor
COctreeSceneNode::~COctreeSceneNode()
{
	if (Shadow)
		Shadow->drop();
	deleteTree();

	for(u32 i = 0; i < StdMeshes.size(); ++i)
		StdMeshes[i]->drop();

	StdMeshes.clear();
}
예제 #30
0
파일: practica2.c 프로젝트: polo070770/SO2
int main(){

	RBTree tree;

	int opcio;

	/* Prints the menu */
	
	do {

		opcio = menuPrincipal();

		switch(opcio){
			case 1:
				printf("\nOpcio1\n");
				creacioArbre(&tree);
				break;
			case 2:
				printf("\nOpcio2\n");
				enmagatzamentArbre(&tree);
				break;
			case 3:
				printf("\nOpcio3\n");
				lecturaArbre(&tree);
				break;
			case 4:
				printf("\nOpcio4\n");

				opcio = menuAnalisisArbre();

				switch(opcio){
					case 1:
						printf("\nSub-opcio1\n");
						probabilitat_Segons_Fitxer(&tree);
						break;
					case 2:
						printf("\nSub-opcio2\n");
						probabilitat_Segons_Nlletres(&tree);
						break;
				}

				break;
		}

	}while(opcio != 5);

	printf("\nFins aviat!\n");

	/*Release the tree memory*/
	if(n_nodes != -1)
		deleteTree(&tree);
	
	return 0;
}