Example #1
0
void treePrint(node p){
    if(p!=NULL){
        treePrint(p->left);
        printf("%3d->", p->b->acc);
        treePrint(p->right);
    }
}
Example #2
0
static void
treePrint(
    tree_sTable *tp,
    tree_sNode  *np,
    tree_sNode  *op,
    tree_sNode  *oop,
    int         level,
    void        (*printNode)(tree_sNode *, int)
    )
{

    if (np == tp->null)
        return;

    if (level > tp->maxDepth)
        tp->maxDepth = level;

    treePrint(tp, np->left, np, np->parent, level+1, printNode);  

    printNode(np, level);

    switch (np->bal) {
    case 1:
        tp->nHP++;
        break;
    case 0:
        tp->nHZ++;
        break;
    case -1:
        tp->nHN++;
        break;
    }

    treePrint(tp, np->right, np, np->parent, level+1, printNode);
}  
Example #3
0
File: print.c Project: bol/boc
int drawTree() {
	struct Process *proc;
	int depth;

	depth = 0;

	proc = first_process;
	while (1) {
		if (proc->colour != 0) {
			treePrint(proc, depth);
		}

		if (proc->first_child) {
			proc = proc->first_child;
			depth++;
			continue;
		} else if (proc->next_sibling) {
			proc = proc->next_sibling;
			continue;
		} else {
			while (proc->next_sibling == NULL) {
				if (proc->parent == NULL) {
					return 0;
				}
				proc = proc->parent;
				depth--;
			}

			proc = proc->next_sibling;
		}
	}

	return -1;
}
Example #4
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);
}
Example #5
0
	void dirTrace(wxString path, TiXmlElement *pFilter) 
	{
		wxFileName f(path);

		TiXmlElement *pNewFilter = newFilter(f.GetName());
		treePrint(f.GetName());

		// link dir
		if (pFilter)
			pFilter->LinkEndChild(pNewFilter);

		m_iTreeLevel++;

		// find files first 
		wxArrayString arrayString;
		int num = GetAllFiles(path, &arrayString);
		for (int i=0; i<num; i++)
			fileTrace(arrayString[i], pNewFilter);

		wxDir dir(path);
		if (!dir.IsOpened()) {
			m_iTreeLevel--;
			return;
		}

		// find directory second
		wxString filename;
		bool cont = dir.GetFirst(&filename, wxEmptyString,  wxDIR_DIRS);
		while(cont) {
			wxString strPath = f.GetPath() + "\\" + f.GetName() + "\\" + filename;
			dirTrace(strPath, pNewFilter);
			cont = dir.GetNext(&filename);
		}
		m_iTreeLevel--;
	}
Example #6
0
	void fileTrace(wxString path, TiXmlElement *pFilter) 
	{
		// todo RelativePath
		TiXmlElement *pNewFile = new TiXmlElement("File");
		pNewFile->SetAttribute("RelativePath", path);
		pFilter->LinkEndChild(pNewFile);
		treePrint(path, false);
	}
Example #7
0
int main(){
    book b = {10, "I2A", "Cormen", 720};
    book b1 = {5, "AA", "KM", 0};    
    book b2 = {7, "A2A", "K2M", 360};
    book b3 = {50, "CP", "DR", 200};
    book b4 = {100, "SM", "RK", 210};
    book b5 = {9, "SM", "RK", 210};
    book b6 = {90, "SM", "RK", 210};

    node tree1 = NULL;
    node binT = insertInBST(tree1, &b);
    binT = insertInBST(binT, &b1);
    binT = insertInBST(binT, &b2);
    binT = insertInBST(binT, &b3);    
    binT = insertInBST(binT, &b4);
    
    // printf("tree1:\n");
    // treePrint(binT);

    printf("\n");
    
    node tree2 = NULL;
    node binT2 = insertInBST(tree2, &b);
    binT2 = insertInBST(binT2, &b1);
    binT2 = insertInBST(binT2, &b2);
    binT2 = insertInBST(binT2, &b3);    
    binT2 = insertInBST(binT2, &b4);
    // binT2 = insertInBST(binT2, &b5);
    // binT2 = insertInBST(binT2, &b6);
    printf("\nbeforedel\ttree2:\n");
    book* maxPrice = findMaxPricedBook(binT2);
    printf("%s written by %s has maximum price, which is %d \n",maxPrice->title, maxPrice->name, maxPrice->price);
    treePrint(binT2);
    deleteNode(binT2, &b2);    
    deleteNode(binT2, &b3); 
    printf("\nafterdel\ttree2:\n");
    treePrint(binT2);
    printf("\n");
    
    printf("\nTest for not found case, should return 0 for not found, returned: %d \n",findNode(binT2, &b4));
    printf("Test for found case, should return 1 for  found, returned: %d \n",findNode(binT2, &b1));
    // node x = searchNode(binT2, &b);
    // printf("Search Node b: %d, %s, %s, %d\n", x->b->acc, x->b->title, x->b->name, x->b->price);

    return 0;
}
Example #8
0
int
main(int argc, char **argv)
{
    Strategy *s;
    Card temp;
    int i;
    int j;
    const int n = 16;
    struct tree handBuiltroot;
    struct tree handBuiltLeft;

    struct tree *root = EMPTY_TREE;

    handBuiltroot.key = 3;
    handBuiltroot.child[LEFT] = &handBuiltLeft;
    handBuiltroot.child[RIGHT] = 0;

    handBuiltLeft.key = 1;
    handBuiltLeft.child[LEFT] = handBuiltLeft.child[RIGHT] = 0;

    treePrint(&handBuiltroot);

    /* new improved tree using treeInsert */
    for(i = 0; i < n; i++) {
        treeInsert(&root, 5*i % n);
        treePrint(root);
    }

    /* get rid of root */
    for(i = 0; i <= n; i++) {
        treeDeleteMin(&root);
        treePrint(root);
    }
    s = strategyCreate(4);
    for (j = 0; j < 10; j++) {
        strategyDeal(s, j);
        if (j % 2 == 0) {
            temp = strategyPlay(s, 3);
        }
    }
    treePrint(s->pile[3]);
    treePrint(s->pile[2]);
    return 0;
}
Example #9
0
int main()
{
	int i, n;
	int num[MAXNUM];
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &num[i]);

	/* Insert one by one, judge the duplication */

	node *root = NULL;	

	for (i = 0; i < n; i++){
		printf("inserting: %d\n", num[i]);
		root = insert(root, &num[i]);
		printf("tree[%d]:\n", i);
		treePrint(root);
	}
	treePrint(root);
}
int main(int argc, char ** argv){
	char x[MAX_SIZE];
	int c ;
	tnode * root = NULL;
	while((c = getword(x, MAX_SIZE)) !=EOF){
		if(isalpha(c)){
			root = addNode(root, x);
		}
	}
	printf("\nthe tree looks like: \n");
	treePrint(root);
}