Exemplo n.º 1
0
Arquivo: maintest.c Projeto: wanglf/ds
int 
main()
{
	/*int treeCount = GetSubnetCount();*/
	switchADT swList[swCount];
	int actualCount = GetSWListFromFile("switch.ini", swList, swCount);
	PtrToTreeNode *trees = malloc(sizeof(PtrToTreeNode) * actualCount);

	int i;
	for (i = 0; i < actualCount; i++) {
		trees[i] = NewTreeNode();
		SetTreeElement(trees[i], swList[i]);
		if (swList[i] -> fatherIndex != -1) {
			AddFirstChild(trees[i], trees[swList[i] -> fatherIndex]);
		}

		if (swList[i] -> leftIndex != -1) {
			AddBrother(trees[i], trees[swList[i] -> leftIndex]);
		}

	}

	preorder(trees[0], visitSwitch);
	printf("---------------------------------\n");
	postorder(trees[0], visitSwitch);

	return EXIT_SUCCESS;
}
Exemplo n.º 2
0
treeNode TopDownTree(long item, unsigned depth)
{
    if (depth > 0) {
        treeNode ret, l, r;
        ret = l = r = NULL;
        GGC_PUSH_3(ret, l, r);

        ret = NewTreeNode(NULL, NULL, item);
        l = TopDownTree(2 * item - 1, depth - 1);
        r = TopDownTree(2 * item, depth - 1);
        GGC_WP(ret, left, l);
        GGC_WP(ret, right, r);

        return ret;
    } else
        return NewTreeNode(NULL, NULL, item);
} /* BottomUpTree() */
Exemplo n.º 3
0
	}
	temp->data = data;
	temp->right = NULL;
	temp->left = NULL;
	temp->parent = NULL;
	return temp;
}