Пример #1
0
int treeSize(Tree t) {

  if(!t)
    return 0;

  return( treeSize(t->left) + treeSize(t->right) + 1 );
}
Пример #2
0
int treeSize(node *ptr){
	static int count = 0;
	if (ptr != NULL)
	{
		treeSize(ptr->left);
		count++;
		treeSize(ptr->right);
	}
	return count;
}
Пример #3
0
// Function to return the size of the binary tree
int treeSize(NodeT *p)
{
	static int iCount = 0;
	if (p != NULL)
	{
		treeSize(p->pLeft);
		iCount++;
		treeSize(p->pRight);
	}
	return iCount;
}
Пример #4
0
/*This function takes in a pointer to a root node and calculates and returns the size of the tree based on the size of its child subtrees*/
static size_t treeCalcSize (const struct node *root) {
	size_t size;

	if (root == 0) { /* root --> size is 0*/
		return 0;
	}
	else { /* root exists --> size = 1 (current node) + size of left and right subtrees*/
		size = 1 + treeSize(root->child[LEFT]) + treeSize(root->child[RIGHT]);
		return size;
	}
}
Пример #5
0
// Compiled fragtree -> compiled fragtree without labels
Node dereference(Node program) {
    int sz = treeSize(program) * 4;
    int labelLength = 1;
    while (sz >= 256) { labelLength += 1; sz /= 256; }
    programAux aux = buildDict(program, Aux(), labelLength);
    return substDict(program, aux, labelLength);
}
Пример #6
0
// Main Function, controls program flow
int main()
{

	NodeT *pRoot;
	int i;
	int k = 0;
	int iAnswer = 0;
	int iSize;

	pRoot = NULL;
	
	pRoot = getNumbers(pRoot);	// Call function to get user input
	
	iSize = treeSize(pRoot);
	
	for (i = 0; i < 1000; i++)
	{
		srand(i*17);
		k = rand()%iSize+1;
		updateKthNum(pRoot, k);		// Call function to update picked number
	}
	
	printf("\nProbabilities after 1000 random selections are:\n");
	
	printTree(pRoot);
	
	freeTreeMem(pRoot);		// Alwys free that allocated memory!!

	printf("\n\n");
	
	return 0;
}
Пример #7
0
void
testStore2(void)
{
	int	i;
	long	bO, bF, grossBytes;
 
	bO = stoBytesAlloc - stoBytesFree - stoBytesGc;
 
	printforest = 1;
	grossBytes = 0;
 
	forest = (struct tree **)stoAlloc(int0,
					  FOREST_SIZE*sizeof(struct tree *));
	for (i = 0; i < FOREST_SIZE; i++) forest[i] = 0;
 
	randomForest();

	for (i = 0; i < FOREST_SIZE; i++) {
		long sz = treeSize(forest[i]);
		printf("%d: %ld bytes\n", i, sz);
		grossBytes += sz;
		if (printforest) treePrint(osStdout, forest[i]);
	}
 
	for (i = 0; i < FOREST_SIZE; i++) {
		treeCheck(forest[i], treeNo);
		treeFree(forest[i]);
	}

	bF = stoBytesAlloc - stoBytesFree - stoBytesGc;
	printf("Memory: %lu (owned) %lu (alloc) %ld (net) %ld (gross)\n",
	       stoBytesOwn, bF - bO, treeBytes, grossBytes);
 
	stoFree(forest);
}
Пример #8
0
// Compiled fragtree -> compiled fragtree without labels
std::vector<Node> dereference(Node program) {
    int sz = treeSize(program) * 4;
    int labelLength = 1;
    while (sz >= 256) { labelLength += 1; sz /= 256; }
    programAux aux = Aux();
    buildDict(program, aux, labelLength);
    std::vector<Node> o;
    substDict(program, aux, labelLength, o);
    return o;
}
Пример #9
0
int main (int argc, char *argv[]){
	//declaring main variables
	node *tree = NULL;
	int treeSz;
	
	tree = getNumbers(tree);
	treeSz = treeSize(tree);
	findKthInt(tree, treeSz);
	freeTree(tree);		
}
Пример #10
0
static void 
treeDup (tree_t* tp, int J)
{
    int M = treeSize(tp);
    int L = treeRoot(tp);
    int LL = prevRoot(tp);
    int i, LS = L + (J-1)*M - 1;
    for (i = L; i <= LS; i++) {
	if ((i-L)%M == 0)  tp->p[i+M] = LL;
	else tp->p[i+M] = tp->p[i] + M;
    }
    tp->top = LS + M;
}
Пример #11
0
// Function to get k from user
int getK(NodeT *p)
{
	int iSize;
	int k = 0;
	
	iSize = treeSize(p);
	
	// Check that k is within the number of entries
	while (k < 1 || k > iSize)
	{
		scanf("%d", &k);
	
		// Check that k is within the number of entries
		if (k < 1 || k > iSize)
			printf("\nPlease enter a positive integer between 1 and %d: ", iSize);
	}
	
	return k;
}
Пример #12
0
static long
treeSize(struct tree *t)
{
	int	i, sz;

        if (!t || t->isSized) return 0;

	t->isSized = 1;

	if (t->isLeaf) {
		sz = sizeof(*t) - sizeof(t) + t->argc * sizeof(char);
	}
	else {
		sz = sizeof(*t) - sizeof(t) + t->argc * sizeof(t);
 
		for (i = 0; i < t->argc; i++)
			sz += treeSize(t->u.argv[i]);
	}
	return sz;
}
Пример #13
0
// Number of tokens in a tree
int treeSize(Node prog) {
    if (prog.type == TOKEN) return 1;
    int o = 0;
	for (unsigned i = 0; i < prog.args.size(); i++) o += treeSize(prog.args[i]);
    return o;
}
 bool isBalanced(TreeNode *root) {
     if (!root) return true;
     return isBalanced(root->left) && isBalanced(root->right) && abs(treeSize(root->left) - treeSize(root->right)) <= 1;
 }
 /**
  * @param root: The root of binary tree.
  * @return: True if this Binary tree is Balanced, or false.
  */
 int treeSize(TreeNode *root) {
     if (!root) return 0;
     return max(treeSize(root->left), treeSize(root->right)) + 1;
 }
Пример #16
0
int treeSize(struct node *root) //zad2
{
    if(!root) return 0;
    return treeSize(root->left) + treeSize(root->right) + 1;
}